| | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 控制器 |
| | | * 控制器 |
| | | * |
| | | * @author BladeX |
| | | * @since 2020-07-19 |
| | |
| | | @ApiOperation(value = "新增", notes = "传入dj") |
| | | public R save(@Valid @RequestBody Energy energy) { |
| | | List<String> list = energyService.selectEnergyTree(energy.getIdentification()); |
| | | if (list==null){ |
| | | EnergyTree energyTree= new EnergyTree(); |
| | | if (list == null) { |
| | | EnergyTree energyTree = new EnergyTree(); |
| | | energyTree.setIdentification(energy.getIdentification()); |
| | | energyTreeService.save(energyTree); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 能量统计 |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/selectTreeNum") |
| | | public R selectTreeNum() { |
| | | Date date=new Date(); |
| | | DateFormat format=new SimpleDateFormat("yyyy-MM-dd"); |
| | | String time=format.format(date); |
| | | Date date = new Date(); |
| | | DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String time = format.format(date); |
| | | List<String> list = energyService.selectTreeNum(time); |
| | | List<List<String>> lists = splitList(list, 3); |
| | | return R.data(lists); |
| | |
| | | |
| | | /** |
| | | * 拾取能量 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/updateEnergyId") |
| | | public R updateEnergyId(String id,String identification,int num) { |
| | | public R updateEnergyId(String id, String identification, int num) { |
| | | |
| | | energyService.updateEnergyId(id,identification); |
| | | energyService.updateEnergyId(id, identification); |
| | | //能量树 |
| | | String nums = energyTreeService.selectNum(identification); |
| | | Integer a=Integer.valueOf(nums); |
| | | Integer n=Integer.valueOf(num); |
| | | Integer a = Integer.valueOf(nums); |
| | | Integer n = Integer.valueOf(num); |
| | | int i1 = n + a; |
| | | String i = String.valueOf(i1); |
| | | energyTreeService.updateEnergyTreeId(i,identification); |
| | | energyTreeService.updateEnergyTreeId(i, identification); |
| | | return R.success("拾取成功"); |
| | | } |
| | | |
| | | /** |
| | | * 拾取能量 |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/updateEnergyIds") |
| | | public R updateEnergyId(@Valid @RequestBody Energy energy) { |
| | | |
| | | energyService.updateEnergyIds(energy.getId(), energy.getIdentification()); |
| | | //能量树 |
| | | String nums = energyTreeService.selectNum(energy.getIdentification()); |
| | | Integer a = Integer.valueOf(nums); |
| | | Integer n = Integer.valueOf(energy.getNum()); |
| | | int i1 = n + a; |
| | | String i = String.valueOf(i1); |
| | | energyTreeService.updateEnergyTreeId(i, energy.getIdentification()); |
| | | return R.success("拾取成功"); |
| | | } |
| | | |
| | | |
| | | private List<List<String>> splitList(List<String> list , int groupSize){ |
| | | private List<List<String>> splitList(List<String> list, int groupSize) { |
| | | int length = list.size(); |
| | | // 计算可以分成多少组 |
| | | int num = ( length + groupSize - 1 )/groupSize ; // TODO |
| | | int num = (length + groupSize - 1) / groupSize; // TODO |
| | | List<List<String>> newList = new ArrayList<>(num); |
| | | for (int i = 0; i < num; i++) { |
| | | // 开始位置 |
| | | int fromIndex = i * groupSize; |
| | | // 结束位置 |
| | | int toIndex = (i+1) * groupSize < length ? ( i+1 ) * groupSize : length ; |
| | | newList.add(list.subList(fromIndex,toIndex)) ; |
| | | int toIndex = (i + 1) * groupSize < length ? (i + 1) * groupSize : length; |
| | | newList.add(list.subList(fromIndex, toIndex)); |
| | | } |
| | | return newList ; |
| | | return newList; |
| | | } |
| | | |
| | | /** |
| | | * 每天23点自动拾取能量 |
| | | * |
| | | */ |
| | | @PostMapping("/pickup") |
| | | public void pickup(String ids,String time,String identification) { |
| | | public void pickup(String ids, String time, String identification) { |
| | | String[] split = ids.split(","); |
| | | String strArrays = ""; |
| | | for (int i = 0; i < split.length; i++) { |
| | | strArrays += "'" + split[i] + "',"; |
| | | } |
| | | String code = strArrays.substring(0, strArrays.length() - 1); |
| | | energyService.updateEnergyType(code,time); |
| | | energyService.updateEnergyType(code, time); |
| | | //能量树 |
| | | String nums = energyTreeService.selectNum(identification); |
| | | Integer a=Integer.valueOf(nums); |
| | | Integer a = Integer.valueOf(nums); |
| | | int length = split.length; |
| | | int i = a + length; |
| | | String num=String.valueOf(i); |
| | | energyTreeService.updateEnergyTreeId(num,identification); |
| | | String num = String.valueOf(i); |
| | | energyTreeService.updateEnergyTreeId(num, identification); |
| | | } |
| | | |
| | | /** |
| | | * 浇水 |
| | | * |
| | | * @param energy |
| | | * @return |
| | | */ |
| | | @PostMapping("/updateTre") |
| | | public R updateTre(@Valid @RequestBody Energy energy) { |
| | | //能量树 |
| | | String nums = energyTreeService.selectNum(energy.getIdentification()); |
| | | Integer a = Integer.valueOf(nums); |
| | | int i1 = a+1; |
| | | String i = String.valueOf(i1); |
| | | energyTreeService.updateEnergyTreeId(i, energy.getIdentification()); |
| | | String nu = energyTreeService.selectNum(energy.getIdentification()); |
| | | return R.data(nu); |
| | | } |
| | | } |