| Line 3... |
Line 3... |
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
4 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
| 5 |
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
|
5 |
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
|
| 6 |
import com.spice.profitmandi.dao.entity.transaction.Seller;
|
6 |
import com.spice.profitmandi.dao.entity.transaction.Seller;
|
| 7 |
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMaster;
|
7 |
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMaster;
|
| - |
|
8 |
import com.spice.profitmandi.dao.enumuration.warehouse.WarehouseStatus;
|
| 8 |
import com.spice.profitmandi.dao.model.warehouse.NewPhysicalWarehouseRequest;
|
9 |
import com.spice.profitmandi.dao.model.warehouse.NewPhysicalWarehouseRequest;
|
| 9 |
import com.spice.profitmandi.dao.model.warehouse.NewSellerRequest;
|
10 |
import com.spice.profitmandi.dao.model.warehouse.NewSellerRequest;
|
| 10 |
import com.spice.profitmandi.dao.model.warehouse.NewWarehouseAddressRequest;
|
11 |
import com.spice.profitmandi.dao.model.warehouse.NewWarehouseAddressRequest;
|
| - |
|
12 |
import com.spice.profitmandi.dao.model.warehouse.PhysicalWarehouseView;
|
| 11 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
13 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 12 |
import com.spice.profitmandi.dao.repository.transaction.SellerRepository;
|
14 |
import com.spice.profitmandi.dao.repository.transaction.SellerRepository;
|
| 13 |
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
|
15 |
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
|
| 14 |
import com.spice.profitmandi.service.SellerService;
|
16 |
import com.spice.profitmandi.service.SellerService;
|
| - |
|
17 |
import com.spice.profitmandi.service.warehouse.SuspendedWarehouseStockAlertService;
|
| 15 |
import com.spice.profitmandi.service.warehouse.WarehouseSetupService;
|
18 |
import com.spice.profitmandi.service.warehouse.WarehouseSetupService;
|
| 16 |
import org.apache.logging.log4j.LogManager;
|
19 |
import org.apache.logging.log4j.LogManager;
|
| 17 |
import org.apache.logging.log4j.Logger;
|
20 |
import org.apache.logging.log4j.Logger;
|
| 18 |
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 19 |
import org.springframework.http.ResponseEntity;
|
22 |
import org.springframework.http.ResponseEntity;
|
| Line 26... |
Line 29... |
| 26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
29 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
30 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 28 |
import org.springframework.web.bind.annotation.RequestParam;
|
31 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 29 |
import org.springframework.web.bind.annotation.ResponseBody;
|
32 |
import org.springframework.web.bind.annotation.ResponseBody;
|
| 30 |
|
33 |
|
| - |
|
34 |
import java.util.EnumMap;
|
| 31 |
import java.util.HashMap;
|
35 |
import java.util.HashMap;
|
| - |
|
36 |
import java.util.List;
|
| 32 |
import java.util.Map;
|
37 |
import java.util.Map;
|
| 33 |
import java.util.stream.Collectors;
|
38 |
import java.util.stream.Collectors;
|
| 34 |
|
39 |
|
| 35 |
/**
|
40 |
/**
|
| 36 |
* Seller / physical warehouse setup screen. Rules live in WarehouseSetupService; this only maps requests to it.
|
41 |
* Seller / physical warehouse setup screen, including each warehouse's status (active / suspended / inactive) and label. Rules live in WarehouseSetupService; this only maps requests to it.
|
| 37 |
*/
|
42 |
*/
|
| 38 |
@Controller
|
43 |
@Controller
|
| 39 |
@Transactional(rollbackFor = Throwable.class)
|
44 |
@Transactional(rollbackFor = Throwable.class)
|
| 40 |
public class SellerController {
|
45 |
public class SellerController {
|
| 41 |
|
46 |
|
| Line 52... |
Line 57... |
| 52 |
private SellerService sellerService;
|
57 |
private SellerService sellerService;
|
| 53 |
|
58 |
|
| 54 |
@Autowired
|
59 |
@Autowired
|
| 55 |
private WarehouseSetupService warehouseSetupService;
|
60 |
private WarehouseSetupService warehouseSetupService;
|
| 56 |
|
61 |
|
| - |
|
62 |
@Autowired
|
| - |
|
63 |
private SuspendedWarehouseStockAlertService suspendedWarehouseStockAlertService;
|
| - |
|
64 |
|
| 57 |
private static final Logger LOGGER = LogManager.getLogger(SellerController.class);
|
65 |
private static final Logger LOGGER = LogManager.getLogger(SellerController.class);
|
| 58 |
|
66 |
|
| 59 |
/**
|
67 |
/**
|
| 60 |
* Realign the INTERNAL stores of a warehouse with the address currently mapped to it.
|
68 |
* Realign the INTERNAL stores of a warehouse with the address currently mapped to it.
|
| 61 |
*
|
69 |
*
|
| Line 78... |
Line 86... |
| 78 |
|
86 |
|
| 79 |
@RequestMapping(value = "/getAllSeller", method = RequestMethod.GET)
|
87 |
@RequestMapping(value = "/getAllSeller", method = RequestMethod.GET)
|
| 80 |
public String getAllSeller(Model model) throws Exception {
|
88 |
public String getAllSeller(Model model) throws Exception {
|
| 81 |
Map<Integer, Long> warehouseCounts = sellerWarehouseRepository.selectAll().stream()
|
89 |
Map<Integer, Long> warehouseCounts = sellerWarehouseRepository.selectAll().stream()
|
| 82 |
.collect(Collectors.groupingBy(x -> x.getSellerId(), Collectors.counting()));
|
90 |
.collect(Collectors.groupingBy(x -> x.getSellerId(), Collectors.counting()));
|
| - |
|
91 |
List<PhysicalWarehouseView> warehouses = warehouseSetupService.getAllPhysicalWarehouses();
|
| - |
|
92 |
Map<WarehouseStatus, Long> statusCounts = new EnumMap<>(WarehouseStatus.class);
|
| - |
|
93 |
for (WarehouseStatus status : WarehouseStatus.values()) {
|
| - |
|
94 |
statusCounts.put(status, warehouses.stream().filter(x -> x.getStatus() == status).count());
|
| - |
|
95 |
}
|
| - |
|
96 |
model.addAttribute("warehouses", warehouses);
|
| - |
|
97 |
model.addAttribute("statusCounts", statusCounts);
|
| - |
|
98 |
model.addAttribute("statuses", WarehouseStatus.values());
|
| 83 |
model.addAttribute("sellers", warehouseSetupService.getSellers());
|
99 |
model.addAttribute("sellers", warehouseSetupService.getSellers());
|
| 84 |
model.addAttribute("warehouseCounts", warehouseCounts);
|
100 |
model.addAttribute("warehouseCounts", warehouseCounts);
|
| 85 |
model.addAttribute("stateNames", this.stateNames());
|
101 |
model.addAttribute("stateNames", this.stateNames());
|
| 86 |
model.addAttribute("states", stateRepository.selectAll());
|
102 |
model.addAttribute("states", stateRepository.selectAll());
|
| 87 |
model.addAttribute("addresses", warehouseSetupService.getAddresses());
|
103 |
model.addAttribute("addresses", warehouseSetupService.getAddresses());
|
| Line 92... |
Line 108... |
| 92 |
public String getSellerWareHouse(@RequestParam(name = "sellerId") int sellerId, Model model) throws Exception {
|
108 |
public String getSellerWareHouse(@RequestParam(name = "sellerId") int sellerId, Model model) throws Exception {
|
| 93 |
Seller seller = sellerRepository.selectById(sellerId);
|
109 |
Seller seller = sellerRepository.selectById(sellerId);
|
| 94 |
model.addAttribute("seller", seller);
|
110 |
model.addAttribute("seller", seller);
|
| 95 |
model.addAttribute("stateNames", this.stateNames());
|
111 |
model.addAttribute("stateNames", this.stateNames());
|
| 96 |
model.addAttribute("warehouses", warehouseSetupService.getPhysicalWarehouses(sellerId));
|
112 |
model.addAttribute("warehouses", warehouseSetupService.getPhysicalWarehouses(sellerId));
|
| - |
|
113 |
model.addAttribute("statuses", WarehouseStatus.values());
|
| 97 |
model.addAttribute("assignableAddresses", warehouseSetupService.getAssignableAddresses(seller.getStateId()));
|
114 |
model.addAttribute("assignableAddresses", warehouseSetupService.getAssignableAddresses(seller.getStateId()));
|
| 98 |
return "seller-warehouse-container";
|
115 |
return "seller-warehouse-container";
|
| 99 |
}
|
116 |
}
|
| 100 |
|
117 |
|
| 101 |
@RequestMapping(value = "/createNewAddress", method = RequestMethod.POST)
|
118 |
@RequestMapping(value = "/createNewAddress", method = RequestMethod.POST)
|
| Line 125... |
Line 142... |
| 125 |
public ResponseEntity<?> createNewWarehouse(@RequestBody NewPhysicalWarehouseRequest request) throws Exception {
|
142 |
public ResponseEntity<?> createNewWarehouse(@RequestBody NewPhysicalWarehouseRequest request) throws Exception {
|
| 126 |
Warehouse warehouse = warehouseSetupService.createPhysicalWarehouse(request);
|
143 |
Warehouse warehouse = warehouseSetupService.createPhysicalWarehouse(request);
|
| 127 |
return ResponseEntity.ok(this.idResponse("warehouseId", warehouse.getId()));
|
144 |
return ResponseEntity.ok(this.idResponse("warehouseId", warehouse.getId()));
|
| 128 |
}
|
145 |
}
|
| 129 |
|
146 |
|
| 130 |
@RequestMapping(value = "/physicalWarehouse/{warehouseId}/active", method = RequestMethod.POST)
|
147 |
@RequestMapping(value = "/physicalWarehouse/{warehouseId}/status", method = RequestMethod.POST)
|
| - |
|
148 |
@ResponseBody
|
| - |
|
149 |
public ResponseEntity<?> setWarehouseStatus(@PathVariable int warehouseId, @RequestParam WarehouseStatus status)
|
| - |
|
150 |
throws Exception {
|
| - |
|
151 |
warehouseSetupService.setWarehouseStatus(warehouseId, status);
|
| - |
|
152 |
return ResponseEntity.ok(this.idResponse("warehouseId", warehouseId));
|
| - |
|
153 |
}
|
| - |
|
154 |
|
| - |
|
155 |
@RequestMapping(value = "/physicalWarehouse/{warehouseId}/displayName", method = RequestMethod.POST)
|
| 131 |
@ResponseBody
|
156 |
@ResponseBody
|
| 132 |
public ResponseEntity<?> setWarehouseActive(@PathVariable int warehouseId, @RequestParam boolean active)
|
157 |
public ResponseEntity<?> setWarehouseDisplayName(@PathVariable int warehouseId, @RequestParam String displayName)
|
| 133 |
throws Exception {
|
158 |
throws Exception {
|
| 134 |
warehouseSetupService.setWarehouseActive(warehouseId, active);
|
159 |
warehouseSetupService.setWarehouseDisplayName(warehouseId, displayName);
|
| 135 |
return ResponseEntity.ok(this.idResponse("warehouseId", warehouseId));
|
160 |
return ResponseEntity.ok(this.idResponse("warehouseId", warehouseId));
|
| 136 |
}
|
161 |
}
|
| 137 |
|
162 |
|
| - |
|
163 |
// Same mail the daily cron sends; from the screen it goes out at once.
|
| - |
|
164 |
@RequestMapping(value = "/warehouseStockAlert/send", method = RequestMethod.POST)
|
| - |
|
165 |
@ResponseBody
|
| - |
|
166 |
public ResponseEntity<?> sendWarehouseStockAlert() throws Exception {
|
| - |
|
167 |
Map<String, Object> response = new HashMap<>();
|
| - |
|
168 |
response.put("summary", suspendedWarehouseStockAlertService.sendAlert());
|
| - |
|
169 |
return ResponseEntity.ok(response);
|
| - |
|
170 |
}
|
| - |
|
171 |
|
| 138 |
@RequestMapping(value = "/physicalWarehouse/{warehouseId}/address", method = RequestMethod.POST)
|
172 |
@RequestMapping(value = "/physicalWarehouse/{warehouseId}/address", method = RequestMethod.POST)
|
| 139 |
@ResponseBody
|
173 |
@ResponseBody
|
| 140 |
public ResponseEntity<?> remapAddress(@PathVariable int warehouseId, @RequestParam int addressId)
|
174 |
public ResponseEntity<?> remapAddress(@PathVariable int warehouseId, @RequestParam int addressId)
|
| 141 |
throws Exception {
|
175 |
throws Exception {
|
| 142 |
warehouseSetupService.remapAddress(warehouseId, addressId);
|
176 |
warehouseSetupService.remapAddress(warehouseId, addressId);
|