| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
- |
|
| 4 |
import java.util.ArrayList;
|
- |
|
| 5 |
import java.util.HashMap;
|
- |
|
| 6 |
import java.util.List;
|
- |
|
| 7 |
import java.util.Map;
|
- |
|
| 8 |
import java.util.stream.Collectors;
|
- |
|
| 9 |
|
- |
|
| 10 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 11 |
|
- |
|
| 12 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 13 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 14 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 15 |
import org.springframework.stereotype.Controller;
|
- |
|
| 16 |
import org.springframework.transaction.annotation.Transactional;
|
- |
|
| 17 |
import org.springframework.ui.Model;
|
- |
|
| 18 |
import org.springframework.web.bind.annotation.RequestMapping;
|
- |
|
| 19 |
import org.springframework.web.bind.annotation.RequestMethod;
|
- |
|
| 20 |
import org.springframework.web.bind.annotation.RequestParam;
|
- |
|
| 21 |
|
- |
|
| 22 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
3 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
| 23 |
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
|
4 |
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
|
| 24 |
import com.spice.profitmandi.dao.entity.transaction.Seller;
|
5 |
import com.spice.profitmandi.dao.entity.transaction.Seller;
|
| 25 |
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
|
6 |
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
|
| 26 |
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMapping;
|
7 |
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMapping;
|
| Line 29... |
Line 10... |
| 29 |
import com.spice.profitmandi.dao.enumuration.inventory.WarehouseType;
|
10 |
import com.spice.profitmandi.dao.enumuration.inventory.WarehouseType;
|
| 30 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
11 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
12 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.transaction.SellerRepository;
|
13 |
import com.spice.profitmandi.dao.repository.transaction.SellerRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
|
14 |
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
|
| 34 |
import com.spice.profitmandi.dao.repository.transaction.WareHouseAddressMappingRepository;
|
15 |
import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMappingRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.transaction.WareHouseAddressMasterRepository;
|
16 |
import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMasterRepository;
|
| - |
|
17 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
18 |
import org.apache.logging.log4j.Logger;
|
| - |
|
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
20 |
import org.springframework.stereotype.Controller;
|
| - |
|
21 |
import org.springframework.transaction.annotation.Transactional;
|
| - |
|
22 |
import org.springframework.ui.Model;
|
| - |
|
23 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| - |
|
24 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| - |
|
25 |
import org.springframework.web.bind.annotation.RequestParam;
|
| - |
|
26 |
|
| - |
|
27 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
28 |
import java.time.LocalDateTime;
|
| - |
|
29 |
import java.util.HashMap;
|
| - |
|
30 |
import java.util.List;
|
| - |
|
31 |
import java.util.Map;
|
| - |
|
32 |
import java.util.stream.Collectors;
|
| 36 |
|
33 |
|
| 37 |
|
34 |
|
| 38 |
@Controller
|
35 |
@Controller
|
| 39 |
@Transactional(rollbackFor = Throwable.class)
|
36 |
@Transactional(rollbackFor = Throwable.class)
|
| 40 |
public class SellerController {
|
37 |
public class SellerController {
|
| Line 48... |
Line 45... |
| 48 |
|
45 |
|
| 49 |
@Autowired
|
46 |
@Autowired
|
| 50 |
WarehouseRepository warehouseRepository;
|
47 |
WarehouseRepository warehouseRepository;
|
| 51 |
|
48 |
|
| 52 |
@Autowired
|
49 |
@Autowired
|
| 53 |
WareHouseAddressMasterRepository wareHouseAddressMasterRepository;
|
50 |
WarehouseAddressMasterRepository warehouseAddressMasterRepository;
|
| 54 |
|
51 |
|
| 55 |
@Autowired
|
52 |
@Autowired
|
| 56 |
private SellerWarehouseRepository sellerWarehouseRepository;
|
53 |
private SellerWarehouseRepository sellerWarehouseRepository;
|
| 57 |
|
54 |
|
| 58 |
@Autowired
|
55 |
@Autowired
|
| 59 |
private WareHouseAddressMappingRepository wareHouseAddressMappingRepository;
|
56 |
private WarehouseAddressMappingRepository warehouseAddressMappingRepository;
|
| 60 |
|
57 |
|
| 61 |
private static final Logger LOGGER = LogManager.getLogger(SellerController.class);
|
58 |
private static final Logger LOGGER = LogManager.getLogger(SellerController.class);
|
| 62 |
|
59 |
|
| 63 |
@RequestMapping(value = "/createNewWarehouse", method = RequestMethod.POST)
|
60 |
@RequestMapping(value = "/createNewWarehouse", method = RequestMethod.POST)
|
| 64 |
public String getViewOurSales(HttpServletRequest request, @RequestParam(name = "address", required = true, defaultValue = "0") int address, @RequestParam(name = "prefix", required = true, defaultValue = "0") String prefix, @RequestParam(name = "sellerId", required = true, defaultValue = "0") int sellerId, @RequestParam(name = "warehouseName", required = true, defaultValue = "0") String warehouseName, @RequestParam(name = "pin", required = true, defaultValue = "0") String pinCode, Model model)
|
61 |
public String getViewOurSales(HttpServletRequest request, @RequestParam(name = "address", required = true, defaultValue = "0") int address, @RequestParam(name = "prefix", required = true, defaultValue = "0") String prefix, @RequestParam(name = "sellerId", required = true, defaultValue = "0") int sellerId, @RequestParam(name = "warehouseName", required = true, defaultValue = "0") String warehouseName, @RequestParam(name = "pin", required = true, defaultValue = "0") String pinCode, Model model)
|
| 65 |
|
62 |
|
| 66 |
throws Exception {
|
63 |
throws Exception {
|
| 67 |
|
64 |
|
| 68 |
Seller seller = sellerRepository.selectById(sellerId);
|
65 |
Seller seller = sellerRepository.selectById(sellerId);
|
| 69 |
WarehouseAddressMaster wam = wareHouseAddressMasterRepository.selectById(address);
|
66 |
WarehouseAddressMaster wam = warehouseAddressMasterRepository.selectById(address);
|
| 70 |
|
67 |
|
| 71 |
Warehouse warehouse = new Warehouse();
|
68 |
Warehouse warehouse = new Warehouse();
|
| 72 |
warehouse.setDisplayName(warehouseName);
|
69 |
warehouse.setDisplayName(warehouseName);
|
| 73 |
warehouse.setLocation(wam.getAddress());
|
70 |
warehouse.setLocation(wam.getAddress());
|
| 74 |
warehouse.setGstin(seller.getGstin());
|
71 |
warehouse.setGstin(seller.getGstin());
|
| Line 106... |
Line 103... |
| 106 |
warehouseAddressMapping.setAddressId(address);
|
103 |
warehouseAddressMapping.setAddressId(address);
|
| 107 |
warehouseAddressMapping.setCreated(LocalDateTime.now());
|
104 |
warehouseAddressMapping.setCreated(LocalDateTime.now());
|
| 108 |
warehouseAddressMapping.setUpdated(null);
|
105 |
warehouseAddressMapping.setUpdated(null);
|
| 109 |
warehouseAddressMapping.setWarehouseId(warehouse.getId());
|
106 |
warehouseAddressMapping.setWarehouseId(warehouse.getId());
|
| 110 |
warehouseAddressMapping.setAddressId(address);
|
107 |
warehouseAddressMapping.setAddressId(address);
|
| 111 |
wareHouseAddressMappingRepository.persist(warehouseAddressMapping);
|
108 |
warehouseAddressMappingRepository.persist(warehouseAddressMapping);
|
| 112 |
|
109 |
|
| 113 |
|
110 |
|
| 114 |
return "seller";
|
111 |
return "seller";
|
| 115 |
|
112 |
|
| 116 |
}
|
113 |
}
|
| Line 139... |
Line 136... |
| 139 |
wham.setPin(pin);
|
136 |
wham.setPin(pin);
|
| 140 |
wham.setStateId(stateId);
|
137 |
wham.setStateId(stateId);
|
| 141 |
wham.setContacNumber("18002700273");
|
138 |
wham.setContacNumber("18002700273");
|
| 142 |
wham.setContactPerson("Customer Care");
|
139 |
wham.setContactPerson("Customer Care");
|
| 143 |
wham.setCreated(LocalDateTime.now());
|
140 |
wham.setCreated(LocalDateTime.now());
|
| 144 |
wareHouseAddressMasterRepository.persist(wham);
|
141 |
warehouseAddressMasterRepository.persist(wham);
|
| 145 |
|
142 |
|
| 146 |
return "seller";
|
143 |
return "seller";
|
| 147 |
|
144 |
|
| 148 |
}
|
145 |
}
|
| 149 |
|
146 |
|
| Line 178... |
Line 175... |
| 178 |
|
175 |
|
| 179 |
List<Integer> sellerwarehouseIds = sellerWarehouse.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());
|
176 |
List<Integer> sellerwarehouseIds = sellerWarehouse.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());
|
| 180 |
|
177 |
|
| 181 |
Map<Integer, WarehouseAddressMaster> wam = null;
|
178 |
Map<Integer, WarehouseAddressMaster> wam = null;
|
| 182 |
if (sellerwarehouseIds.size() > 0) {
|
179 |
if (sellerwarehouseIds.size() > 0) {
|
| 183 |
List<WarehouseAddressMapping> warehouseAddressMapping = wareHouseAddressMappingRepository.selectAllByIds(sellerwarehouseIds);
|
180 |
List<WarehouseAddressMapping> warehouseAddressMapping = warehouseAddressMappingRepository.selectAllByIds(sellerwarehouseIds);
|
| 184 |
wam = mapWarhouseIdAndAddress(warehouseAddressMapping);
|
181 |
wam = mapWarhouseIdAndAddress(warehouseAddressMapping);
|
| 185 |
} else {
|
182 |
} else {
|
| 186 |
wam = new HashMap<>();
|
183 |
wam = new HashMap<>();
|
| 187 |
}
|
184 |
}
|
| 188 |
|
185 |
|
| Line 197... |
Line 194... |
| 197 |
|
194 |
|
| 198 |
private Map<Integer, WarehouseAddressMaster> mapWarhouseIdAndAddress(
|
195 |
private Map<Integer, WarehouseAddressMaster> mapWarhouseIdAndAddress(
|
| 199 |
List<WarehouseAddressMapping> warehouseAddressMapping) {
|
196 |
List<WarehouseAddressMapping> warehouseAddressMapping) {
|
| 200 |
Map<Integer, WarehouseAddressMaster> wam = new HashMap<>();
|
197 |
Map<Integer, WarehouseAddressMaster> wam = new HashMap<>();
|
| 201 |
for (WarehouseAddressMapping wa : warehouseAddressMapping) {
|
198 |
for (WarehouseAddressMapping wa : warehouseAddressMapping) {
|
| 202 |
WarehouseAddressMaster wm = wareHouseAddressMasterRepository.selectById(wa.getAddressId());
|
199 |
WarehouseAddressMaster wm = warehouseAddressMasterRepository.selectById(wa.getAddressId());
|
| 203 |
wam.put(wa.getWarehouseId(), wm);
|
200 |
wam.put(wa.getWarehouseId(), wm);
|
| 204 |
}
|
201 |
}
|
| 205 |
|
202 |
|
| 206 |
return wam;
|
203 |
return wam;
|
| 207 |
}
|
204 |
}
|