5b88541a0f720d8f3f2bc8ac644b3d4429afcf85.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. package cn.com.goldenwater.dcproj.service.impl.tac;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.dao.BisInspAllRlationPersDao;
  4. import cn.com.goldenwater.dcproj.dao.TacAttPawpBaseChangeLogDao;
  5. import cn.com.goldenwater.dcproj.dao.TacAttPawpBaseDao;
  6. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchObjDao;
  7. import cn.com.goldenwater.dcproj.model.DingChuanTacProject;
  8. import cn.com.goldenwater.dcproj.model.TacAttPawpBase;
  9. import cn.com.goldenwater.dcproj.model.TacAttPawpBaseChangeLog;
  10. import cn.com.goldenwater.dcproj.model.TacInspYearBatchObj;
  11. import cn.com.goldenwater.dcproj.model.WorkInxMonth;
  12. import cn.com.goldenwater.dcproj.param.TacAttPawpBaseParam;
  13. import cn.com.goldenwater.dcproj.param.TacInspYearBatchObjParam;
  14. import cn.com.goldenwater.dcproj.service.TacAttPawpBaseService;
  15. import cn.com.goldenwater.dcproj.utils.GeoUtil;
  16. import cn.com.goldenwater.dcproj.utils.expExcel.ExcelExport;
  17. import cn.com.goldenwater.dcproj.utils.expExcel.ExportAbstract;
  18. import cn.com.goldenwater.dcproj.utils.expExcel.ExportUtil;
  19. import cn.com.goldenwater.id.util.UuidUtil;
  20. import cn.com.goldenwater.target.CheckException;
  21. import io.swagger.annotations.ApiModelProperty;
  22. import org.apache.commons.lang3.ArrayUtils;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import javax.servlet.http.HttpServletResponse;
  30. import java.beans.BeanInfo;
  31. import java.beans.Introspector;
  32. import java.beans.PropertyDescriptor;
  33. import java.lang.reflect.Field;
  34. import java.lang.reflect.Method;
  35. import java.text.SimpleDateFormat;
  36. import java.time.LocalDateTime;
  37. import java.util.ArrayList;
  38. import java.util.Calendar;
  39. import java.util.Date;
  40. import java.util.HashMap;
  41. import java.util.List;
  42. import java.util.Map;
  43. import java.util.Objects;
  44. /**
  45. * @author lune
  46. * @date 2019-6-19
  47. */
  48. @Service
  49. @Transactional
  50. public class TacAttPawpBaseServiceImpl extends AbstractCrudService<TacAttPawpBase, TacAttPawpBaseParam> implements TacAttPawpBaseService {
  51. private static Logger logger = LoggerFactory.getLogger(TacAttPawpBaseServiceImpl.class);
  52. @Autowired
  53. private TacAttPawpBaseDao tacAttPawpBaseDao;
  54. @Autowired
  55. private TacAttPawpBaseChangeLogDao tacAttPawpBaseChangeLogDao;
  56. @Autowired
  57. private BisInspAllRlationPersDao rlationPersDao;
  58. @Autowired
  59. private TacInspYearBatchObjDao tacInspYearBatchObjDao;
  60. public TacAttPawpBaseServiceImpl(TacAttPawpBaseDao tacAttPawpBaseDao) {
  61. super(tacAttPawpBaseDao);
  62. this.tacAttPawpBaseDao = tacAttPawpBaseDao;
  63. }
  64. @Override
  65. public int insert(TacAttPawpBase tacAttPawpBase) {
  66. int ret = 0;
  67. if (tacAttPawpBase.getCenterX() != null && tacAttPawpBase.getGdX() == null) {
  68. Map<String, Double> map = GeoUtil.wgs84togcj02(tacAttPawpBase.getCenterX(), tacAttPawpBase.getCenterY());
  69. tacAttPawpBase.setGdX(map.get("lon"));
  70. tacAttPawpBase.setGdY(map.get("lat"));
  71. } else if (tacAttPawpBase.getCenterX() == null && tacAttPawpBase.getGdX() != null) {
  72. Map<String, Double> map = GeoUtil.gcj02towgs84(tacAttPawpBase.getGdX(), tacAttPawpBase.getGdY());
  73. tacAttPawpBase.setCenterX(map.get("lon"));
  74. tacAttPawpBase.setCenterY(map.get("lat"));
  75. }
  76. ret = tacAttPawpBaseDao.insert(tacAttPawpBase);
  77. return ret;
  78. }
  79. @Override
  80. public int update(TacAttPawpBase tacAttPawpBase) {
  81. int ret = 0;
  82. if (tacAttPawpBase.getCenterX() != null && tacAttPawpBase.getGdX() == null) {
  83. Map<String, Double> map = GeoUtil.wgs84togcj02(tacAttPawpBase.getCenterX(), tacAttPawpBase.getCenterY());
  84. tacAttPawpBase.setGdX(map.get("lon"));
  85. tacAttPawpBase.setGdY(map.get("lat"));
  86. } else if (tacAttPawpBase.getCenterX() == null && tacAttPawpBase.getGdX() != null) {
  87. Map<String, Double> map = GeoUtil.gcj02towgs84(tacAttPawpBase.getGdX(), tacAttPawpBase.getGdY());
  88. tacAttPawpBase.setCenterX(map.get("lon"));
  89. tacAttPawpBase.setCenterY(map.get("lat"));
  90. }
  91. TacAttPawpBase tacAttPawpBaseOld = tacAttPawpBaseDao.get(tacAttPawpBase.getId());
  92. //调整项记录
  93. StringBuffer contentbuffer = showContent(tacAttPawpBaseOld, tacAttPawpBase);
  94. //调整年度计划工程日志
  95. TacAttPawpBaseChangeLog tacAttPawpBaseChangeLog = new TacAttPawpBaseChangeLog();
  96. tacAttPawpBaseChangeLog.setId(UuidUtil.uuid());
  97. tacAttPawpBaseChangeLog.setYear(tacAttPawpBase.getYear());
  98. tacAttPawpBaseChangeLog.setOjbId(tacAttPawpBase.getId());
  99. tacAttPawpBaseChangeLog.setOjbName(tacAttPawpBase.getName());
  100. tacAttPawpBaseChangeLog.setChangeReson(tacAttPawpBase.getChangeReson());
  101. tacAttPawpBaseChangeLog.setIntm(new Date());
  102. tacAttPawpBaseChangeLog.setPersId(tacAttPawpBase.getPersId());
  103. tacAttPawpBaseChangeLog.setPersName(rlationPersDao.get(tacAttPawpBase.getPersId()).getPersName());
  104. tacAttPawpBaseChangeLog.setContent(contentbuffer.toString());
  105. tacAttPawpBaseChangeLog.setProvince(tacAttPawpBase.getProvince());
  106. tacAttPawpBaseChangeLogDao.insert(tacAttPawpBaseChangeLog);
  107. //修改年度计划工程项目
  108. tacAttPawpBase.setUptm(new Date());
  109. ret = tacAttPawpBaseDao.update(tacAttPawpBase);
  110. return ret;
  111. }
  112. @Override
  113. public List<String> getBaseType(TacAttPawpBaseParam attPawpBaseParam) {
  114. List<String> list = tacAttPawpBaseDao.getBaseType(attPawpBaseParam);
  115. return list;
  116. }
  117. @Override
  118. public int deleteNew(TacAttPawpBaseParam tacAttPawpBaseParam) {
  119. // 判断项目是否分配给稽查组
  120. TacInspYearBatchObjParam tacInspYearBatchObjParam = new TacInspYearBatchObjParam();
  121. tacInspYearBatchObjParam.setOjbId(tacAttPawpBaseParam.getId());
  122. tacInspYearBatchObjParam.setProvince(tacAttPawpBaseParam.getProvince());
  123. List<TacInspYearBatchObj> batchObjList = this.tacInspYearBatchObjDao.findList(tacInspYearBatchObjParam);
  124. if(null != batchObjList && batchObjList.size()>0){
  125. throw new CheckException("此项目已加入稽查组,请先把项目从组里删除!!!");
  126. }
  127. TacAttPawpBase tacAttPawpBase = tacAttPawpBaseDao.get(tacAttPawpBaseParam.getId());
  128. //调整年度计划工程日志
  129. TacAttPawpBaseChangeLog tacAttPawpBaseChangeLog = new TacAttPawpBaseChangeLog();
  130. tacAttPawpBaseChangeLog.setId(UuidUtil.uuid());
  131. tacAttPawpBaseChangeLog.setYear(tacAttPawpBase.getYear());
  132. tacAttPawpBaseChangeLog.setOjbId(tacAttPawpBase.getId());
  133. tacAttPawpBaseChangeLog.setOjbName(tacAttPawpBase.getName());
  134. tacAttPawpBaseChangeLog.setIntm(new Date());
  135. if (StringUtils.isNotBlank(tacAttPawpBaseParam.getPersId())) {
  136. tacAttPawpBaseChangeLog.setPersId(tacAttPawpBaseParam.getPersId());
  137. tacAttPawpBaseChangeLog.setPersName(rlationPersDao.get(tacAttPawpBaseParam.getPersId()).getPersName());
  138. }
  139. tacAttPawpBaseChangeLog.setContent("删除" + tacAttPawpBase.getName() + "工程");
  140. tacAttPawpBaseChangeLog.setProvince(tacAttPawpBaseParam.getProvince());
  141. tacAttPawpBaseChangeLogDao.insert(tacAttPawpBaseChangeLog);
  142. return this.tacAttPawpBaseDao.delete(tacAttPawpBaseParam.getId());
  143. }
  144. @Override
  145. public List<WorkInxMonth> getMonthPro(String adCode, Integer year, Integer month, String province, String tm) {
  146. //获取年度任务数和完成数
  147. List<WorkInxMonth> workInxMonths = tacAttPawpBaseDao.getMonthPro(adCode, year, province, month);
  148. for (WorkInxMonth workInxMonth : workInxMonths) {
  149. workInxMonth.setTimeYear(year);
  150. workInxMonth.setTimeMonth(month);
  151. workInxMonth.setTimeRecord(tm);
  152. //workInxMonth.setInxNumValue(workInxMonth.getInxStatValue());
  153. workInxMonth.setInxStatus("1");
  154. }
  155. return workInxMonths;
  156. }
  157. @Override
  158. public List<DingChuanTacProject> getAllPrject(String year) {
  159. //根据年份获取所有最后阶段项目
  160. List<DingChuanTacProject> dingChuanTacProjects = tacAttPawpBaseDao.getAllPrject(year);
  161. return dingChuanTacProjects;
  162. }
  163. @Override
  164. public List<Map<String, Object>> getJcDescData(String rgstrId) {
  165. List<Map<String, Object>> jcDescData = tacAttPawpBaseDao.getJcDescData(rgstrId);
  166. return jcDescData;
  167. }
  168. /**
  169. * 获取两个对象同名属性内容不相同的列表
  170. *
  171. * @param class1 对象1
  172. * @param class2 对象2
  173. * @return
  174. * @throws ClassNotFoundException
  175. * @throws IllegalAccessException
  176. */
  177. public static List<Map<String, Object>> compareTwoClass(Object class1, Object class2) throws ClassNotFoundException, IllegalAccessException {
  178. List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); //获取对象的class
  179. SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
  180. Class<?> clazz1 = class1.getClass();
  181. Class<?> clazz2 = class2.getClass(); //获取对象的属性列表
  182. Field[] field1 = clazz1.getDeclaredFields();
  183. Field[] field2 = clazz2.getDeclaredFields(); //遍历属性列表field1
  184. for (int i = 0; i < field1.length; i++) { //遍历属性列表field2
  185. for (int j = 0; j < field2.length; j++) { //如果field1[i]属性名与field2[j]属性名内容相同
  186. if (field1[i].getName().equals(field2[j].getName())) {
  187. field1[i].setAccessible(true);
  188. field2[j].setAccessible(true); //如果field1[i]属性值与field2[j]属性值内容不相同
  189. if (!compareTwo(field1[i].get(class1), field2[j].get(class2))) {
  190. Map<String, Object> map2 = new HashMap<String, Object>();
  191. if (field1[i].getAnnotation(ApiModelProperty.class) != null) {
  192. map2.put("name", field1[i].getAnnotation(ApiModelProperty.class).value());
  193. if (field1[i].get(class1) != null && field1[i].get(class1) instanceof Date && field2[j].get(class2) != null && field2[j].get(class2) instanceof Date) {
  194. map2.put("old", fmt.format(field1[i].get(class1)));
  195. map2.put("new", fmt.format(field2[j].get(class2)));
  196. } else if (field1[i].get(class1) != null && field1[i].get(class1) instanceof Date) {
  197. map2.put("old", fmt.format(field1[i].get(class1)));
  198. } else if (field2[j].get(class2) != null && field2[j].get(class2) instanceof Date) {
  199. map2.put("new", fmt.format(field2[j].get(class2)));
  200. } else {
  201. map2.put("old", field1[i].get(class1));
  202. map2.put("new", field1[j].get(class2));
  203. }
  204. }
  205. list.add(map2);
  206. }
  207. break;
  208. }
  209. }
  210. }
  211. return list;
  212. }
  213. //对比两个数据是否内容相同
  214. public static boolean compareTwo(Object object1, Object object2) {
  215. if (object1 == null && object2 == null) {
  216. return true;
  217. } //以下注掉代码,看具体需求。因有时会出现源数据是没有进行赋值,因此是null;而通过EditText获取值的时候,虽然没有值,但是会变成"",但是本质是没有赋值的。
  218. if (object1 == "" && object2 == null) {
  219. return true;
  220. }
  221. if (object1 == null && object2 == "") {
  222. return true;
  223. }
  224. if (object1 == null && object2 != null) {
  225. return false;
  226. }
  227. if (object1 != null && object2 == null) {
  228. return true;
  229. }
  230. if (object1 != null && object2 == "") {
  231. return true;
  232. }
  233. if (object1.equals(object2)) {
  234. return true;
  235. }
  236. return false;
  237. }
  238. //对比两个数据是否内容相同
  239. public static StringBuffer showContent(Object tacAttPawpBaseOld, Object tacAttPawpBase) {
  240. //对比两个对象的属性值是否相同,不相同记录调整值
  241. StringBuffer contentbuffer = new StringBuffer();
  242. try {
  243. List<Map<String, Object>> maps = compareTwoClass(tacAttPawpBaseOld, tacAttPawpBase);
  244. for (Map<String, Object> map : maps) {
  245. if (map.get("name") != null && map.get("name") != "") {
  246. contentbuffer.append(map.get("name")).append(":");
  247. if (map.get("old") != null && map.get("new") != null) {
  248. contentbuffer.append(map.get("old")).append("修改值为").append(map.get("new")).append(",");
  249. } else if (map.get("old") == null) {
  250. contentbuffer.append("添加值为").append(map.get("new"));
  251. }
  252. }
  253. }
  254. } catch (ClassNotFoundException | IllegalAccessException e) {
  255. logger.error(e.getMessage(), e);
  256. }
  257. return contentbuffer;
  258. }
  259. public static void main(String[] args) {
  260. TacAttPawpBase tacAttPawpBaseOld = new TacAttPawpBase();
  261. tacAttPawpBaseOld.setId("12345");
  262. tacAttPawpBaseOld.setAdCode("23232");
  263. tacAttPawpBaseOld.setLocation("23232");
  264. TacAttPawpBase tacAttPawpBaseNew = new TacAttPawpBase();
  265. tacAttPawpBaseNew.setId("12345");
  266. tacAttPawpBaseNew.setAdCode("23232");
  267. try {
  268. List<Map<String, Object>> maps = compareTwoClass(tacAttPawpBaseOld, tacAttPawpBaseNew);
  269. StringBuffer contentbuffer = new StringBuffer();
  270. for (Map<String, Object> map : maps) {
  271. System.out.println(contentbuffer.append(map.get("name")).append(map.get("old")).append(map.get("new")));
  272. }
  273. } catch (ClassNotFoundException e) {
  274. e.printStackTrace();
  275. } catch (IllegalAccessException e) {
  276. e.printStackTrace();
  277. }
  278. }
  279. /**
  280. * 导出列表
  281. * @param attPawpBaseParam
  282. * @param response
  283. */
  284. @Override
  285. public void export(TacAttPawpBaseParam attPawpBaseParam, HttpServletResponse response){
  286. // 查询导出的数据
  287. List<TacAttPawpBase> attPawpBaseList = this.tacAttPawpBaseDao.findList(attPawpBaseParam);
  288. List<String> columns = new ArrayList<String>() {{
  289. add("name");
  290. add("type");
  291. add("location");
  292. add("commencementDate");
  293. add("totalInvestment");
  294. }};
  295. exportExcel(attPawpBaseList, response, "稽察年度计划项目列表", columns, TacAttPawpBase.class);
  296. }
  297. public void exportExcel(List<?> result, HttpServletResponse response, String fileName, List<String> list, Class cla) {
  298. if (list == null || list.size() == 0) {
  299. ExportUtil.exportExcel(result, response, fileName);
  300. return;
  301. }
  302. List<Map<String, Object>> mapList = new ArrayList<>();
  303. result.forEach(worker -> mapList.add(transBean2Map(worker)));
  304. ExportAbstract export = new ExcelExport();
  305. if (StringUtils.isBlank(fileName)) {
  306. fileName = "结果列表";
  307. }
  308. export.setFileName(fileName);
  309. export.setExport_ps_export(true);
  310. export.setExport_ps_type(ExportAbstract.XLS);
  311. export.setExport_bzip(false);
  312. export.setTitle(fileName);
  313. ArrayList<Object> cols = new ArrayList<Object>();
  314. Field[] fields = cla.getDeclaredFields();
  315. Class clazz = cla.getSuperclass();
  316. if (clazz != null && clazz != Objects.class) {
  317. fields = ArrayUtils.addAll(fields, clazz.getDeclaredFields());
  318. }
  319. for (String name : list) {
  320. for (Field field : fields) {
  321. if (name.equals(field.getName()) && field.getAnnotation(ApiModelProperty.class) != null) {
  322. field.setAccessible(true);
  323. cols.add(field.getName() + "[" + ExportUtil.fileFormat(field.getAnnotation(ApiModelProperty.class).value()) + "]");
  324. break;
  325. }
  326. }
  327. }
  328. if (cols.size() < 1) {
  329. cols.add("name[名称]");
  330. cols.add("code[编码]");
  331. }
  332. export.setCols(cols);
  333. export.setGroupable(false);
  334. // 设置视图指标
  335. export.setLevel(1);
  336. export.setLocksize(0);
  337. try {
  338. export.Export(response);
  339. // 导出表头
  340. export.ExportHeadForCustom(response);
  341. export.ContinueExport(mapList);
  342. export.EndExport();
  343. } catch (Exception e) {
  344. e.printStackTrace();
  345. }
  346. }
  347. private Map<String, Object> transBean2Map(Object obj) {
  348. if (obj == null) {
  349. return null;
  350. }
  351. Map<String, Object> map = new HashMap<String, Object>();
  352. try {
  353. BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
  354. PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
  355. String key="";
  356. for (PropertyDescriptor property : propertyDescriptors) {
  357. key = property.getName();
  358. // 过滤class属性
  359. if (!"class".equals(key)) {
  360. // 得到property对应的getter方法
  361. Method getter = property.getReadMethod();
  362. Object value = getter.invoke(obj);
  363. map.put(key, value);
  364. if("totalInvestment".equals(key)){
  365. if(null != value && StringUtils.isNotBlank(value.toString())){
  366. map.put(key, value.toString());
  367. }else {
  368. map.put(key, "");
  369. }
  370. }else if("commencementDate".equals(key)){
  371. if(null != value && StringUtils.isNotBlank(value.toString())){
  372. LocalDateTime localDateTime = convertDateToLocalDateTime((Date)value);
  373. if(null != localDateTime){
  374. String dateStr = String.format("%d年%d月%d日",localDateTime.getYear(),localDateTime.getMonthValue(),localDateTime.getDayOfMonth());
  375. map.put(key, dateStr);
  376. }else {
  377. map.put(key, "");
  378. }
  379. }
  380. }
  381. }
  382. }
  383. } catch (Exception e) {
  384. System.out.println("transBean2Map Error " + e);
  385. }
  386. return map;
  387. }
  388. private LocalDateTime convertDateToLocalDateTime(Date date){
  389. Calendar calendar = Calendar.getInstance();
  390. calendar.setTime(date);
  391. LocalDateTime localDateTime = LocalDateTime.of(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH),0,0,0);
  392. return localDateTime;
  393. }
  394. }