|
@@ -1,34 +1,42 @@
|
|
package com.huimv.admin.timer;
|
|
package com.huimv.admin.timer;
|
|
|
|
|
|
|
|
|
|
-import cn.hutool.core.codec.Base64;
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
-import cn.hutool.json.JSONObject;
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
-import com.huimv.admin.common.utils.Digests;
|
|
|
|
-import com.huimv.admin.common.utils.HttpClientSSLUtils;
|
|
|
|
import com.huimv.admin.entity.*;
|
|
import com.huimv.admin.entity.*;
|
|
import com.huimv.admin.entity.zengxindto.*;
|
|
import com.huimv.admin.entity.zengxindto.*;
|
|
import com.huimv.admin.service.*;
|
|
import com.huimv.admin.service.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
|
-import org.springframework.http.*;
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
+
|
|
|
|
+import javax.crypto.Mac;
|
|
|
|
+import javax.crypto.SecretKey;
|
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.net.URL;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.security.GeneralSecurityException;
|
|
|
|
+import java.security.MessageDigest;
|
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
|
+import java.text.DecimalFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
-@Configuration
|
|
|
|
@EnableScheduling
|
|
@EnableScheduling
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/test")
|
|
public class ShenChanTimer {
|
|
public class ShenChanTimer {
|
|
|
|
|
|
//生产数据
|
|
//生产数据
|
|
@@ -36,82 +44,287 @@ public class ShenChanTimer {
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
@Autowired
|
|
@Autowired
|
|
private IProdStockService prodStockService;
|
|
private IProdStockService prodStockService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IProdSaleService prodSaleService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IProdYearOutPigService prodYearOutPigService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IProdMonthOutPigService prodMonthOutPigService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IProdWarningInfoService prodWarningInfoService;
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
-// @Scheduled(cron = "0 0 */4 * * ? ")
|
|
|
|
- @Scheduled(cron = "0 0 * * * ?")
|
|
|
|
-// @GetMapping("/test")
|
|
|
|
- private void getShenChan() throws Exception {
|
|
|
|
- String token = login();
|
|
|
|
- DateTime dateTime = DateUtil.beginOfDay(new Date());
|
|
|
|
- String data = getList(token);
|
|
|
|
|
|
+ // @Scheduled(cron = "0 * * * * ? ")
|
|
|
|
+// @Scheduled(cron = "1 0 * * * ?")
|
|
|
|
+ @GetMapping("/test")
|
|
|
|
+ @Transactional
|
|
|
|
+ public void getShenChan() throws Exception {
|
|
|
|
+ StockLoginDto stockLoginDto = login();
|
|
|
|
+// DateTime dateTime = DateUtil.beginOfDay(new Date());
|
|
|
|
+ String data = getList(stockLoginDto.getToken(),stockLoginDto.getApp_secret());
|
|
ProdStockDto prodStockDto = JSONUtil.toBean(data, ProdStockDto.class);
|
|
ProdStockDto prodStockDto = JSONUtil.toBean(data, ProdStockDto.class);
|
|
List<List<Object>> stockData = prodStockDto.getData();
|
|
List<List<Object>> stockData = prodStockDto.getData();
|
|
|
|
+ DateTime beginOfYear = DateUtil.beginOfYear(DateUtil.offsetMonth(new Date(), -10));
|
|
|
|
+ System.out.println(beginOfYear);
|
|
|
|
+ for (int i = 0; i < 390; i++) {
|
|
|
|
+ DateTime dateTime = DateUtil.offsetDay(beginOfYear, i);
|
|
|
|
+ System.out.println("dateTime--"+dateTime);
|
|
|
|
|
|
for (List stock : stockData) {
|
|
for (List stock : stockData) {
|
|
|
|
+ System.out.println("stock -->"+stock);
|
|
switch (stock.get(0).toString()) {
|
|
switch (stock.get(0).toString()) {
|
|
case "正康":
|
|
case "正康":
|
|
- saveProdStrok(21,stock,dateTime);
|
|
|
|
|
|
+ saveProdStrok(stockLoginDto,21,stock,dateTime);
|
|
break;
|
|
break;
|
|
case "东阳":
|
|
case "东阳":
|
|
- saveProdStrok(24,stock,dateTime);
|
|
|
|
|
|
+ saveProdStrok(stockLoginDto,24,stock,dateTime);
|
|
break;
|
|
break;
|
|
case "浦江":
|
|
case "浦江":
|
|
- saveProdStrok(23,stock,dateTime);
|
|
|
|
|
|
+ saveProdStrok(stockLoginDto,23,stock,dateTime);
|
|
break;
|
|
break;
|
|
case "横路":
|
|
case "横路":
|
|
- saveProdStrok(26,stock,dateTime);
|
|
|
|
|
|
+ saveProdStrok(stockLoginDto,26,stock,dateTime);
|
|
break;
|
|
break;
|
|
case "天台":
|
|
case "天台":
|
|
- saveProdStrok(27,stock,dateTime);
|
|
|
|
|
|
+ saveProdStrok(stockLoginDto,27,stock,dateTime);
|
|
break;
|
|
break;
|
|
case "平望":
|
|
case "平望":
|
|
- saveProdStrok(28,stock,dateTime);
|
|
|
|
|
|
+ saveProdStrok(stockLoginDto,28,stock,dateTime);
|
|
break;
|
|
break;
|
|
case "张村":
|
|
case "张村":
|
|
- saveProdStrok(29,stock,dateTime);
|
|
|
|
|
|
+ saveProdStrok(stockLoginDto,29,stock,dateTime);
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case "三亩田":
|
|
|
|
+ break;
|
|
|
|
+ case "下各":
|
|
|
|
+ break;
|
|
|
|
+ case "瓦窑头":
|
|
|
|
+ break;
|
|
|
|
+ case "莲花":
|
|
|
|
+ break;
|
|
|
|
+ case "里塘":
|
|
|
|
+ break;
|
|
|
|
+ case "苍坑":
|
|
|
|
+ break;
|
|
|
|
+ case "同壮":
|
|
|
|
+ break;
|
|
|
|
+ case "瑞溪":
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
//保存存栏
|
|
//保存存栏
|
|
- private void saveProdStrok(Integer farmId,List stock,DateTime dateTime) {
|
|
|
|
|
|
+ private void saveProdStrok(StockLoginDto stockLoginDto,Integer farmId,List stock,DateTime dateTime) throws Exception {
|
|
|
|
+
|
|
ProdStock prodStock = prodStockService.getOne(new QueryWrapper<ProdStock>().ge("creat_time", dateTime).eq("farm_id", farmId).orderByDesc("creat_time").last("limit 1"));
|
|
ProdStock prodStock = prodStockService.getOne(new QueryWrapper<ProdStock>().ge("creat_time", dateTime).eq("farm_id", farmId).orderByDesc("creat_time").last("limit 1"));
|
|
Boolean isNew = false;
|
|
Boolean isNew = false;
|
|
if(ObjectUtil.isEmpty(prodStock)){
|
|
if(ObjectUtil.isEmpty(prodStock)){
|
|
prodStock = new ProdStock();
|
|
prodStock = new ProdStock();
|
|
isNew = true;
|
|
isNew = true;
|
|
}
|
|
}
|
|
- prodStock.setHbzcl(Integer.parseInt(stock.get(3).toString()));
|
|
|
|
- prodStock.setGzcl(Integer.parseInt(stock.get(4).toString()));
|
|
|
|
- prodStock.setKhzcl(Integer.parseInt(stock.get(6).toString()));
|
|
|
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
|
+ for (int i = 1; i < 17; i++) {
|
|
|
|
+ list.add(getInt(stock.get(i)));
|
|
|
|
+ }
|
|
|
|
+ Integer ZCL = list.get(15);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //后备猪
|
|
|
|
+ prodStock.setHbzcl(list.get(2));
|
|
|
|
+ //公猪存栏 后备公猪+种公猪
|
|
|
|
+ prodStock.setGzcl(list.get(2)+list.get(0));
|
|
|
|
+ //空怀
|
|
|
|
+ prodStock.setKhzcl(list.get(5));
|
|
|
|
+ //仔猪
|
|
|
|
+ prodStock.setZzcl(list.get(11));
|
|
|
|
+ //保育猪存栏
|
|
|
|
+ prodStock.setByzcl(list.get(12));
|
|
|
|
+ //育肥猪存栏
|
|
|
|
+ Integer yfzcl = list.get(14);
|
|
|
|
+
|
|
|
|
+ prodStock.setYfzcl(yfzcl);
|
|
|
|
+ //总存栏
|
|
|
|
+ prodStock.setZcl(ZCL);
|
|
|
|
+ //母猪存栏 后备母猪+怀孕+空怀+流产+返情+分娩+断奶
|
|
|
|
+ prodStock.setMzcl(list.get(1)+list.get(4)+list.get(5)+list.get(6)+list.get(7)+list.get(8)+list.get(9));
|
|
|
|
+ //哺乳猪存栏 仔猪
|
|
|
|
+ prodStock.setBrzcl(list.get(11));
|
|
|
|
+ //妊娠猪存栏 ->分娩
|
|
|
|
+ prodStock.setRszcl(list.get(8));
|
|
|
|
+ //妊娠猪存栏 ->断奶
|
|
|
|
+ prodStock.setBrmzcl(list.get(9));
|
|
|
|
+ //商品猪存栏 保育猪+育肥猪
|
|
|
|
+ prodStock.setSpzcl(list.get(12)+list.get(13));
|
|
|
|
+ prodStock.setDong3(0);
|
|
|
|
+ prodStock.setDong4(0);
|
|
|
|
+ if ( ZCL<15000){
|
|
|
|
+ Integer dong1 = ZCL /3;
|
|
|
|
+ prodStock.setDong1(dong1);
|
|
|
|
+ prodStock.setDong2(ZCL -dong1);
|
|
|
|
+ }else {
|
|
|
|
+ Integer dong1 = 14931 /6;
|
|
|
|
+ Integer dong2 = 14931 /4;
|
|
|
|
+ Integer dong3 = 14931 /5;
|
|
|
|
+ prodStock.setDong1(dong1);
|
|
|
|
+ prodStock.setDong2(dong2);
|
|
|
|
+ prodStock.setDong3(dong3);
|
|
|
|
+ prodStock.setDong4(ZCL -dong1 -dong2 -dong3);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String jinZhudata = getListJz(stockLoginDto.getToken(),stockLoginDto.getApp_secret(),"rep_yz_hm_jc",dateTime);
|
|
|
|
+ ProdStockDto jz2 = JSONUtil.toBean(jinZhudata, ProdStockDto.class);
|
|
|
|
+
|
|
|
|
+ String sw = getListJz(stockLoginDto.getToken(),stockLoginDto.getApp_secret(),"rep_yz_hm_sw",dateTime);
|
|
|
|
+ ProdStockDto sw2 = JSONUtil.toBean(sw, ProdStockDto.class);
|
|
|
|
+
|
|
|
|
+ String xs = getListJz(stockLoginDto.getToken(),stockLoginDto.getApp_secret(),"rep_yz_hm_xs",dateTime);
|
|
|
|
+ ProdStockDto xs2 = JSONUtil.toBean(xs, ProdStockDto.class);
|
|
|
|
+
|
|
|
|
+ List<List<Object>> jzdata = jz2.getData();
|
|
|
|
+ List<List<Object>> swdata = sw2.getData();
|
|
|
|
+ List<List<Object>> sxdata = xs2.getData();
|
|
|
|
+ Integer intjz = ObjectUtil.isEmpty(jzdata) ? 0:Integer.parseInt(jzdata.get(0).get(3).toString());
|
|
|
|
+ Integer intsw = ObjectUtil.isEmpty(swdata) ? 0:Integer.parseInt(swdata.get(0).get(3).toString());
|
|
|
|
+ Integer intsx = ObjectUtil.isEmpty(sxdata) ? 0:Integer.parseInt(sxdata.get(0).get(3).toString());
|
|
|
|
+
|
|
|
|
+ prodStock.setOutPig(intsw+intsx);
|
|
|
|
+ prodStock.setInPig(intjz);
|
|
|
|
+ DateTime beginOfMonth = DateUtil.beginOfMonth(dateTime);
|
|
|
|
+ DateTime beginOfYear = DateUtil.beginOfYear(dateTime);
|
|
|
|
+ Integer monthInPig = prodStockService.sumInPig(farmId,beginOfMonth);
|
|
|
|
+ Integer monthOutPig = prodStockService.sumOutPig(farmId,beginOfMonth,DateUtil.endOfMonth(dateTime));
|
|
|
|
+ Integer yearInPig = prodStockService.sumInPig(farmId,beginOfYear);
|
|
|
|
+ Integer yearOutPig = prodStockService.sumOutPig(farmId,beginOfYear,DateUtil.endOfYear(dateTime));
|
|
|
|
+ prodStock.setMonthInPig(monthInPig);
|
|
|
|
+ prodStock.setMonthOutPig(monthOutPig);
|
|
|
|
+ prodStock.setYearInPig(yearInPig);
|
|
|
|
+ prodStock.setYearOutPig(yearOutPig);
|
|
|
|
+ prodStock.setSiPig(intsw);
|
|
|
|
+ DecimalFormat df = new DecimalFormat("#.##");
|
|
|
|
+
|
|
|
|
+ double percentage = calculatePercentage(ZCL-intsw, ZCL);
|
|
|
|
+ prodStock.setCheng(df.format(percentage));
|
|
|
|
+ DateTime dateTime1 = DateUtil.offsetDay(dateTime, -1);
|
|
|
|
+ ProdStock prodStockZr = prodStockService.getOne(new QueryWrapper<ProdStock>().between("creat_time",dateTime1 ,dateTime).eq("farm_id", farmId).orderByDesc("creat_time").last("limit 1"));
|
|
|
|
+ Integer zryf = 0;
|
|
|
|
+ Integer zrInpig = 0;
|
|
|
|
+ Integer zrOntpig = 0;
|
|
|
|
+ if (ObjectUtil.isNotEmpty(prodStockZr)){
|
|
|
|
+ zryf = prodStockZr.getYfzcl();
|
|
|
|
+ zrInpig = prodStockZr.getInPig();
|
|
|
|
+ zrOntpig = prodStockZr.getOutPig();
|
|
|
|
+ }
|
|
|
|
+ if (ObjectUtil.isEmpty(yfzcl)){
|
|
|
|
+ yfzcl = 0;
|
|
|
|
+ }
|
|
|
|
+ prodStock.setYfcz(yfzcl-zryf);
|
|
|
|
+ prodStock.setInpigcz(intjz- zrInpig);
|
|
|
|
+ prodStock.setOutpigcz(intsw+intsx-zrOntpig);
|
|
|
|
+ prodStock.setZryf(zryf);
|
|
|
|
+ prodStock.setZrinpig(zrInpig);
|
|
|
|
+ prodStock.setZroutpig(zrOntpig);
|
|
|
|
|
|
- prodStock.setZzcl(Integer.parseInt(stock.get(12).toString()));
|
|
|
|
- prodStock.setByzcl(Integer.parseInt(stock.get(13).toString()));
|
|
|
|
- prodStock.setYfzcl(Integer.parseInt(stock.get(15).toString()));
|
|
|
|
- prodStock.setZcl(Integer.parseInt(stock.get(16).toString()));
|
|
|
|
|
|
|
|
if (isNew) {
|
|
if (isNew) {
|
|
- prodStock.setMzcl(100);
|
|
|
|
- prodStock.setBrzcl(452);
|
|
|
|
- prodStock.setRszcl(30);
|
|
|
|
- prodStock.setBrmzcl(20);
|
|
|
|
- prodStock.setSpzcl(1020);
|
|
|
|
- prodStock.setCreatTime(new Date());
|
|
|
|
|
|
+ prodStock.setCreatTime(dateTime);
|
|
prodStock.setDisplayType(0);
|
|
prodStock.setDisplayType(0);
|
|
prodStock.setFarmId(farmId);
|
|
prodStock.setFarmId(farmId);
|
|
prodStockService.save(prodStock);
|
|
prodStockService.save(prodStock);
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
prodStockService.updateById(prodStock);
|
|
prodStockService.updateById(prodStock);
|
|
}
|
|
}
|
|
|
|
+ //本月出栏
|
|
|
|
+ ProdMonthOutPig prodMonthOutPig = prodMonthOutPigService.getOne(new QueryWrapper<ProdMonthOutPig>().ge("date_time",beginOfMonth ).eq("farm_id", farmId).orderByDesc("date_time").last("limit 1"));
|
|
|
|
+
|
|
|
|
+ Integer zyOutPig = prodStockService.sumOutPig(farmId, DateUtil.offsetMonth(beginOfMonth, -1), beginOfMonth);
|
|
|
|
+ if (ObjectUtil.isEmpty(prodMonthOutPig)){
|
|
|
|
+ prodMonthOutPig = new ProdMonthOutPig();
|
|
|
|
+ prodMonthOutPig.setDateTime(beginOfMonth);
|
|
|
|
+ prodMonthOutPig.setFarmId(farmId);
|
|
|
|
+ prodMonthOutPig.setOutPig(monthOutPig);
|
|
|
|
+ prodMonthOutPig.setOutPigCz(monthOutPig -zyOutPig);
|
|
|
|
+ prodMonthOutPig.setZrPig(zyOutPig);
|
|
|
|
+ prodMonthOutPigService.save(prodMonthOutPig);
|
|
|
|
+ }else {
|
|
|
|
+ prodMonthOutPig.setOutPig(monthOutPig);
|
|
|
|
+ prodMonthOutPig.setOutPigCz(monthOutPig -zyOutPig);
|
|
|
|
+ prodMonthOutPig.setZrPig(zyOutPig);
|
|
|
|
+ prodMonthOutPigService.updateById(prodMonthOutPig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //本年出栏
|
|
|
|
+ ProdYearOutPig prodYearOutPig = prodYearOutPigService.getOne(new QueryWrapper<ProdYearOutPig>().ge("date_time", beginOfYear).eq("farm_id", farmId).orderByDesc("date_time").last("limit 1"));
|
|
|
|
+
|
|
|
|
+ Integer zYearOutPig = prodStockService.sumOutPig(farmId, DateUtil.offsetMonth(beginOfYear, -12), beginOfYear);
|
|
|
|
+ if (ObjectUtil.isEmpty(prodYearOutPig)){
|
|
|
|
+ prodYearOutPig = new ProdYearOutPig();
|
|
|
|
+ prodYearOutPig.setDateTime(beginOfYear);
|
|
|
|
+ prodYearOutPig.setFarmId(farmId);
|
|
|
|
+ prodYearOutPig.setOutPig(yearOutPig);
|
|
|
|
+ prodYearOutPig.setOutPigCz(yearOutPig -zYearOutPig);
|
|
|
|
+ prodYearOutPig.setZrPig(zyOutPig);
|
|
|
|
+ prodYearOutPigService.save(prodYearOutPig);
|
|
|
|
+ }else {
|
|
|
|
+ prodYearOutPig.setOutPig(yearOutPig);
|
|
|
|
+ prodYearOutPig.setOutPigCz(yearOutPig -zYearOutPig);
|
|
|
|
+ prodYearOutPig.setZrPig(zyOutPig);
|
|
|
|
+ prodYearOutPigService.updateById(prodYearOutPig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //预警
|
|
|
|
+ ProdWarningInfo prodWarningInfo = prodWarningInfoService.getOne(new QueryWrapper<ProdWarningInfo>().ge("date", dateTime).eq("farm_id", farmId).orderByDesc("date").last("limit 1"));
|
|
|
|
+ if (ObjectUtil.isEmpty(prodWarningInfo)){
|
|
|
|
+ prodWarningInfo = new ProdWarningInfo();
|
|
|
|
+
|
|
|
|
+ prodWarningInfo.setDate( LocalDateTime.now());
|
|
|
|
+ prodWarningInfo.setFarmId(farmId);
|
|
|
|
+ prodWarningInfo.setWarningContent("今日淘汰"+intsw+"头猪");
|
|
|
|
+ prodWarningInfo.setWarningType(1);
|
|
|
|
+ prodWarningInfoService.save(prodWarningInfo);
|
|
|
|
+ }else {
|
|
|
|
+ prodWarningInfo.setWarningContent("今日淘汰"+intsw+"头猪");
|
|
|
|
+ prodYearOutPigService.updateById(prodYearOutPig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //销售
|
|
|
|
+ ProdSale one = prodSaleService.getOne(new QueryWrapper<ProdSale>().ge("creat_time", dateTime).eq("farm_id", farmId).orderByDesc("creat_time").last("limit 1"));
|
|
|
|
+ if(ObjectUtil.isEmpty(one)){
|
|
|
|
+ one = new ProdSale();
|
|
|
|
+ one.setCreatTime(dateTime);
|
|
|
|
+ one.setDisplayType(0);
|
|
|
|
+ one.setFarmId(farmId);
|
|
|
|
+ one.setSaleMoney("0");
|
|
|
|
+ one.setSaleQuantity(intsx);
|
|
|
|
+ prodSaleService.save(one);
|
|
|
|
+ }else {
|
|
|
|
+ one.setSaleQuantity(intsx);
|
|
|
|
+ prodSaleService.updateById(one);
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- //获取数据
|
|
|
|
- private String getList(String token) throws Exception {
|
|
|
|
|
|
+ public static double calculatePercentage(double part, double whole) {
|
|
|
|
+
|
|
|
|
+ return (part / whole) * 100;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ private Integer getInt(Object o) {
|
|
|
|
+ return ObjectUtil.isEmpty(o) ? 0:Integer.parseInt(o.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取数据 生猪数据
|
|
|
|
+ private String getList(String token,String secret) throws Exception {
|
|
|
|
+
|
|
String time = LocalDate.now().toString();
|
|
String time = LocalDate.now().toString();
|
|
String url = "http://test.htpig.cn/rest/db/storedproc";
|
|
String url = "http://test.htpig.cn/rest/db/storedproc";
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
@@ -125,41 +338,171 @@ public class ShenChanTimer {
|
|
list.add(maps);
|
|
list.add(maps);
|
|
map.put("params", list);
|
|
map.put("params", list);
|
|
String params = JSON.toJSONString(map);
|
|
String params = JSON.toJSONString(map);
|
|
- String data = HttpClientSSLUtils.doPost(url + "?token=" + token + "&data=", params);
|
|
|
|
- return data;
|
|
|
|
|
|
+
|
|
|
|
+ LocalDateTime timestamp = LocalDateTime.now();
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ // 格式化日期时间为字符串
|
|
|
|
+ String formattedDateTime = timestamp.format(formatter);
|
|
|
|
+ Map<String,String> tokenMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ tokenMap.put("token",token);
|
|
|
|
+ tokenMap.put("data",params);
|
|
|
|
+ tokenMap.put("sign_method","md5");
|
|
|
|
+ tokenMap.put("timestamp",formattedDateTime);
|
|
|
|
+ tokenMap.put("version","2.0");
|
|
|
|
+ String sign = signTopRequest(tokenMap, secret, "md5");
|
|
|
|
+ tokenMap.put("sign",sign);
|
|
|
|
+ String url1 = url + "?token=" + token + "&sign_method=md5" + "×tamp=" + formattedDateTime + "&version=2.0" + "&sign=" + sign + "&data={data}" ;
|
|
|
|
+ String forObject = restTemplate.getForObject(url1 , String.class,params);
|
|
|
|
+ ProdStockDto prodStockDto = JSONUtil.toBean(forObject, ProdStockDto.class);
|
|
|
|
+
|
|
|
|
+ return forObject;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取数据 进猪数据
|
|
|
|
+ private String getListJz(String token,String secret,String proc_name,DateTime dateTime) throws Exception {
|
|
|
|
+ String time1 = LocalDate.now().toString();
|
|
|
|
+ String time2 = LocalDate.now().toString();
|
|
|
|
+ String url = "http://test.htpig.cn/rest/db/storedproc";
|
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
+ map.put("db_name", "MSSQL");
|
|
|
|
+ map.put("proc_name", proc_name);
|
|
|
|
+ map.put("method", "open_proc");
|
|
|
|
+ List list = new ArrayList();
|
|
|
|
+ HashMap<String, Object> maps = new HashMap<>();
|
|
|
|
+ maps.put("name", "@fdate1");
|
|
|
|
+ maps.put("value", dateTime.toString().substring(0,10));
|
|
|
|
+ HashMap<String, Object> maps2 = new HashMap<>();
|
|
|
|
+ maps2.put("name", "@fdate2");
|
|
|
|
+ maps2.put("value", dateTime.toString().substring(0,10));
|
|
|
|
+ list.add(maps);
|
|
|
|
+ list.add(maps2);
|
|
|
|
+ map.put("params", list);
|
|
|
|
+ String params = JSON.toJSONString(map);
|
|
|
|
+
|
|
|
|
+ LocalDateTime timestamp = LocalDateTime.now();
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ // 格式化日期时间为字符串
|
|
|
|
+ String formattedDateTime = timestamp.format(formatter);
|
|
|
|
+ Map<String,String> tokenMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ tokenMap.put("token",token);
|
|
|
|
+ tokenMap.put("data",params);
|
|
|
|
+ tokenMap.put("sign_method","md5");
|
|
|
|
+ tokenMap.put("timestamp",formattedDateTime);
|
|
|
|
+ tokenMap.put("version","2.0");
|
|
|
|
+ String sign = signTopRequest(tokenMap, secret, "md5");
|
|
|
|
+ tokenMap.put("sign",sign);
|
|
|
|
+ String url1 = url + "?token=" + token + "&sign_method=md5" + "×tamp=" + formattedDateTime + "&version=2.0" + "&sign=" + sign + "&data={data}" ;
|
|
|
|
+ String forObject = restTemplate.getForObject(url1 , String.class,params);
|
|
|
|
+ return forObject;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
public static void main(String[] args) throws Exception {
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
+
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
|
|
StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
|
|
String token = stockLoginDto.getToken();
|
|
String token = stockLoginDto.getToken();
|
|
|
|
+ String secret = stockLoginDto.getApp_secret();
|
|
|
|
+
|
|
String time = LocalDate.now().toString();
|
|
String time = LocalDate.now().toString();
|
|
String url = "http://test.htpig.cn/rest/db/storedproc";
|
|
String url = "http://test.htpig.cn/rest/db/storedproc";
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("db_name", "MSSQL");
|
|
map.put("db_name", "MSSQL");
|
|
map.put("proc_name", "rep_yz_kc_hz");
|
|
map.put("proc_name", "rep_yz_kc_hz");
|
|
map.put("method", "open_proc");
|
|
map.put("method", "open_proc");
|
|
|
|
+
|
|
HashMap<String, Object> maps = new HashMap<>();
|
|
HashMap<String, Object> maps = new HashMap<>();
|
|
List list = new ArrayList();
|
|
List list = new ArrayList();
|
|
maps.put("name", "@fdate");
|
|
maps.put("name", "@fdate");
|
|
maps.put("value", time);
|
|
maps.put("value", time);
|
|
list.add(maps);
|
|
list.add(maps);
|
|
-
|
|
|
|
map.put("params", list);
|
|
map.put("params", list);
|
|
|
|
+
|
|
String params = JSON.toJSONString(map);
|
|
String params = JSON.toJSONString(map);
|
|
- System.out.println(" ====== getStock请求参数:【" + params + "】");
|
|
|
|
- String data = HttpClientSSLUtils.doPost(url + "?token=" + token + "&data=", params);
|
|
|
|
- ProdStockDto prodStockDto = JSONUtil.toBean(data, ProdStockDto.class);
|
|
|
|
|
|
+ LocalDateTime timestamp = LocalDateTime.now();
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ // 格式化日期时间为字符串
|
|
|
|
+ String formattedDateTime = timestamp.format(formatter);
|
|
|
|
+ Map<String,String> tokenMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ tokenMap.put("token",token);
|
|
|
|
+ tokenMap.put("data",params);
|
|
|
|
+ tokenMap.put("sign_method","md5");
|
|
|
|
+ tokenMap.put("timestamp",formattedDateTime);
|
|
|
|
+ tokenMap.put("version","2.0");
|
|
|
|
+ String sign = signTopRequest(tokenMap, secret, "md5");
|
|
|
|
+ tokenMap.put("sign",sign);
|
|
|
|
+ formattedDateTime.replace(" ","%20");
|
|
|
|
+ String url1 = url + "?token=" + token + "&sign_method=md5" + "×tamp=" + formattedDateTime + "&version=2.0" + "&sign=" + sign + "&data={data}" ;
|
|
|
|
+ System.out.println(url1);
|
|
|
|
+// String data = HttpClientSSLUtils.doPost(url1,JSON.toJSONString(params));
|
|
|
|
+ RestTemplate restTemplate1 = new RestTemplate();
|
|
|
|
+
|
|
|
|
+ String forObject = restTemplate.getForObject(url1 , String.class,params);
|
|
|
|
+ ProdStockDto prodStockDto = JSONUtil.toBean(forObject, ProdStockDto.class);
|
|
|
|
+ System.out.println(prodStockDto);
|
|
}
|
|
}
|
|
|
|
+ public static String signTopRequest(Map<String, String> params, String secret, String signMethod) throws IOException {
|
|
|
|
+ // 第一步:检查参数是否已经排序
|
|
|
|
+ String[] keys = params.keySet().toArray(new String[0]);
|
|
|
|
+ Arrays.sort(keys);
|
|
|
|
+
|
|
|
|
+ // 第二步:把所有参数名和参数值串在一起
|
|
|
|
+ StringBuilder query = new StringBuilder();
|
|
|
|
+ query.append(secret);
|
|
|
|
+ for (String key : keys) {
|
|
|
|
+ String value = params.get(key);
|
|
|
|
+ query.append(key).append(value);
|
|
|
|
+ }
|
|
|
|
+ query.append(secret);
|
|
|
|
+
|
|
|
|
+ // 第三步:使用MD5/HMAC加密
|
|
|
|
+ byte[] bytes;
|
|
|
|
+
|
|
|
|
+ bytes = encryptMD5(query.toString());
|
|
|
|
|
|
- private String login() throws Exception {
|
|
|
|
|
|
+ // 第四步:把二进制转化为大写的十六进制(正确签名应该为32大写字符串,此方法需要时使用)
|
|
|
|
+ return byte2hex(bytes);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static byte[] encryptMD5(String data) throws IOException {
|
|
|
|
+ return encryptMD5(data.getBytes("UTF-8"));
|
|
|
|
+ }
|
|
|
|
+ public static byte[] encryptMD5(byte[] data) throws IOException {
|
|
|
|
+ byte[] bytes = null;
|
|
|
|
+ try {
|
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
|
+ bytes = md.digest(data);
|
|
|
|
+ } catch (GeneralSecurityException gse) {
|
|
|
|
+ throw new IOException(gse.toString());
|
|
|
|
+ }
|
|
|
|
+ return bytes;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private StockLoginDto login() throws Exception {
|
|
StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
|
|
StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
|
|
|
|
+ System.out.println(stockLoginDto.toString());
|
|
if (stockLoginDto.getStatus() != 0) {
|
|
if (stockLoginDto.getStatus() != 0) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- return stockLoginDto.getToken();
|
|
|
|
|
|
+ return stockLoginDto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static String byte2hex(byte[] bytes) {
|
|
|
|
+ StringBuilder sign = new StringBuilder();
|
|
|
|
+ for (int i = 0; i < bytes.length; i++) {
|
|
|
|
+ String hex = Integer.toHexString(bytes[i] & 0xFF);if (hex.length() == 1) { sign.append("0");
|
|
|
|
+ }sign.append(hex.toUpperCase()); }return sign.toString();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|