ea978a1ea668302e3e085383717f600ab3204737.svn-base 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. package cn.com.goldenwater.dcproj.service.impl.ducha;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.constValue.AdCodeLabel;
  4. import cn.com.goldenwater.dcproj.constValue.CommonLabel;
  5. import cn.com.goldenwater.dcproj.dao.*;
  6. import cn.com.goldenwater.dcproj.dto.*;
  7. import cn.com.goldenwater.dcproj.enums.SystemFlagEnum;
  8. import cn.com.goldenwater.dcproj.model.*;
  9. import cn.com.goldenwater.dcproj.param.*;
  10. import cn.com.goldenwater.dcproj.service.*;
  11. import cn.com.goldenwater.dcproj.util.CheckUtil;
  12. import cn.com.goldenwater.dcproj.util.StatisticalUtil;
  13. import cn.com.goldenwater.dcproj.utils.*;
  14. import cn.com.goldenwater.id.util.UuidUtil;
  15. import cn.com.goldenwater.target.CheckException;
  16. import cn.com.goldenwater.util.common.IPUtils;
  17. import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
  18. import com.github.pagehelper.PageHelper;
  19. import com.github.pagehelper.PageInfo;
  20. import net.sf.json.JSONObject;
  21. import org.apache.commons.collections.MapUtils;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.apache.cxf.endpoint.Client;
  24. import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
  25. import org.slf4j.Logger;
  26. import org.slf4j.LoggerFactory;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.beans.factory.annotation.Value;
  29. import org.springframework.data.redis.core.RedisTemplate;
  30. import org.springframework.stereotype.Service;
  31. import org.springframework.transaction.annotation.Transactional;
  32. import org.springframework.util.Assert;
  33. import javax.imageio.ImageIO;
  34. import javax.servlet.http.HttpServletRequest;
  35. import java.awt.*;
  36. import java.awt.font.FontRenderContext;
  37. import java.awt.geom.Rectangle2D;
  38. import java.awt.image.BufferedImage;
  39. import java.io.File;
  40. import java.net.InetAddress;
  41. import java.net.UnknownHostException;
  42. import java.util.List;
  43. import java.util.*;
  44. import java.util.concurrent.TimeUnit;
  45. /**
  46. * @author zhaohg
  47. * @date 2019-2-23
  48. */
  49. @Service
  50. @Transactional
  51. public class BisInspAllRlationPersServiceImpl extends AbstractCrudService<BisInspAllRlationPers, BisInspAllRlationPersParam> implements BisInspAllRlationPersService {
  52. @Autowired
  53. private BisInspAllRlationPersDao bisInspAllRlationPersDao;
  54. @Autowired
  55. private UserRoleDao userRoleDao;
  56. @Autowired
  57. private BisInspPersOrgService bisInspPersOrgService;
  58. @Autowired
  59. private SupervisionPlanDao supervisionPlanDao;
  60. @Autowired
  61. private OlBisInspOrgDao olBisInspOrgDao;
  62. @Autowired
  63. private RedisTemplate redisTemplate;
  64. @Value("${btMessageServiceUrl}")
  65. public String btMessageServiceUrl;
  66. @Autowired
  67. public PersPositionLatestDao persPositionLatestDao;
  68. @Autowired
  69. private BisInspPlanDpService bisInspPlanDpService;
  70. @Autowired
  71. private BisInspAllService bisInspAllService;
  72. public BisInspAllRlationPersServiceImpl(BisInspAllRlationPersDao bisInspAllRlationPersDao) {
  73. super(bisInspAllRlationPersDao);
  74. this.bisInspAllRlationPersDao = bisInspAllRlationPersDao;
  75. }
  76. private static String apiKey = "1036432406699048960";
  77. //
  78. private static String apiSecrect = "bbSsX1wvmaKdca5x2+yBDgeFtl9hj4zJmnegunWuLuHLwLo+QjxOr3//P4BJNrVADa7tN4w0DX1KS/VSec5G0x+ucDeAcSt9tWgFGyoBVtblybh+vzLbwH4sJa92hQfu\n";
  79. private Logger logger = LoggerFactory.getLogger(getClass());
  80. @Autowired
  81. private DdMessageDao ddMessageDao;
  82. @Value("${api.url}")
  83. private String apiUrl;
  84. @Value("${sms.template}")
  85. private String smsTemplate;
  86. @Value("${sms.bak.template}")
  87. private String bakTemplate;
  88. @Value("${work.url}")
  89. private String workUrl;
  90. @Value("${sms.mwr.aliyun}")
  91. private String smsMwrAliyun;
  92. @Override
  93. public BisInspAllRlationPers createUser(BisInspAllRlationPers bisInspAllRlationPers) {
  94. CheckUtil.notEmpty(bisInspAllRlationPers.getPersName(), "人员姓名为必填参数");
  95. if (StringUtils.isBlank(bisInspAllRlationPers.getOwnerSystem())) {
  96. bisInspAllRlationPers.setOwnerSystem("DC_ALL");
  97. }
  98. bisInspAllRlationPers.setGuid(UuidUtil.uuid());
  99. BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
  100. param.setMobilenumb(bisInspAllRlationPers.getMobilenumb());
  101. List list = findList(param);
  102. if (list != null && list.size() > 0) {
  103. throw new CheckException("用户不能重复添加");
  104. }
  105. addPreOrg(bisInspAllRlationPers);
  106. //密码MD5加密
  107. if (StringUtils.isNotBlank(bisInspAllRlationPers.getPwd())) {
  108. bisInspAllRlationPers.setPwd(MD5.getMD5(aesUtil.desEncrypt(bisInspAllRlationPers.getPwd().replace(" ", "+"))));
  109. }
  110. insert(bisInspAllRlationPers);
  111. //添加人员到小鱼账号
  112. return bisInspAllRlationPers;
  113. }
  114. private void addPreOrg(BisInspAllRlationPers bisInspAllRlationPers) {
  115. //先删除授权,再添加机构授权
  116. BisInspPersOrgParam persOrgParam = new BisInspPersOrgParam();
  117. persOrgParam.setPersId(bisInspAllRlationPers.getGuid());
  118. persOrgService.deleteBy(persOrgParam);
  119. if (StringUtils.isNotBlank(bisInspAllRlationPers.getOrgId())) {
  120. OlBisInspOrg olBisInspOrg = olBisInspOrgDao.get(bisInspAllRlationPers.getOrgId());
  121. if (olBisInspOrg != null) {
  122. bisInspAllRlationPers.setOrgNm(olBisInspOrg.getOrgNm());
  123. bisInspAllRlationPers.setProvince(olBisInspOrg.getAdCode());
  124. }
  125. BisInspPersOrg inspPersOrg = new BisInspPersOrg();
  126. inspPersOrg.setOrgId(bisInspAllRlationPers.getOrgId());
  127. inspPersOrg.setPersId(bisInspAllRlationPers.getGuid());
  128. if (StringUtils.isNotBlank(bisInspAllRlationPers.getPersType())) {
  129. inspPersOrg.setUserType(bisInspAllRlationPers.getPersType());
  130. } else {
  131. inspPersOrg.setUserType(AdCodeLabel.GROUP_LEADER);
  132. }
  133. BisInspPersOrgParam bisInspPersOrgParam = new BisInspPersOrgParam();
  134. bisInspPersOrgParam.setPersId(inspPersOrg.getPersId());
  135. bisInspPersOrgParam.setOrgId(inspPersOrg.getOrgId());
  136. if (null == persOrgService.getBy(bisInspPersOrgParam)) {
  137. persOrgService.insert(inspPersOrg);
  138. }
  139. }
  140. }
  141. @Override
  142. public boolean sendMessage(String phone) throws Exception {
  143. BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
  144. param.setMobilenumb(phone);
  145. BisInspAllRlationPers pers = bisInspAllRlationPersDao.getBy(param);
  146. if (null != pers && StringUtils.isNotBlank(pers.getGuid())) {
  147. String key = "sms:" + phone;
  148. Object value = redisTemplate.opsForValue().get(key);
  149. if (value == null) {
  150. value = 1;
  151. }
  152. Integer intValue = Integer.valueOf(String.valueOf(value));
  153. String smsTemp = smsTemplate;
  154. if (intValue.intValue() >= 5) {
  155. smsTemp = bakTemplate;
  156. }
  157. Map<String, String> params = new HashMap<String, String>();
  158. Random rand = new Random();
  159. int num = rand.nextInt(900000) + 100000;
  160. String code = num + "";
  161. params.put("apiKey", apiKey);
  162. params.put("apiSecrect", apiSecrect);
  163. params.put("templateParam", "{\"code\":\"" + code + "\"}");
  164. params.put("signName", "金水云平台");
  165. params.put("templeteCode", smsTemp);//SMS_158547721
  166. params.put("mobile", phone);
  167. System.out.println("发送短信前:" + phone);
  168. logger.info("发送短信前:" + phone);
  169. SendSmsResponse sendSmsResponse = null;
  170. try {
  171. String content = "";
  172. if ("0".equals(smsMwrAliyun)) {
  173. sendSmsResponse = SmsUtil.send(params.get("mobile"), params.get("templateParam"), params.get("apiSecrect"), params.get("templeteCode"), params.get("signName"));
  174. content = sendSmsResponse.getMessage();
  175. System.out.println("发送短信后:" + content);
  176. logger.info("发送短信后:" + content);
  177. }
  178. if ("1".equals(smsMwrAliyun)) {
  179. content = HttpClientUtils.doHttpsPost2(apiUrl + "/sms/send", params, new HashMap<>());
  180. //互联网短信平台 或者 106短信
  181. System.out.println("发送短信后:" + content);
  182. logger.info("发送短信后:" + content);
  183. } else if ("2".equals(smsMwrAliyun)) {//调用新疆兵团短信服务
  184. content = sendMsgByBtMessgaeService(phone, "本次登录水利监管工作平台验证码为:" + code + ",有效时间5分钟!");
  185. System.out.println("发送短信后:" + content);
  186. logger.info("发送短信后:" + content);
  187. }
  188. } catch (Exception e) {
  189. e.printStackTrace();
  190. }
  191. DdMessage ddMessage = new DdMessage();
  192. ddMessage.setId(UuidUtil.uuid());
  193. ddMessage.setPhone(phone);
  194. ddMessage.setCode(code);
  195. ddMessage.setAccessTime(new Date());
  196. ddMessageDao.insert(ddMessage);
  197. Object keyValue = redisTemplate.opsForValue().get(key);
  198. if (keyValue == null) {
  199. redisTemplate.boundValueOps(key).increment(1);
  200. redisTemplate.boundValueOps(key).expire(1, TimeUnit.HOURS);
  201. } else {
  202. redisTemplate.boundValueOps(key).increment(1);
  203. }
  204. return true;
  205. }
  206. return false;
  207. }
  208. public String sendMsgByBtMessgaeService(String phone, String content) {
  209. JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
  210. Client client = dcf.createClient(btMessageServiceUrl);
  211. Object[] objects;
  212. try {
  213. objects = client.invoke("sendSms", "sjjggzpt", phone, content);
  214. return objects[0].toString();
  215. } catch (java.lang.Exception e) {
  216. e.printStackTrace();
  217. }
  218. return "";
  219. }
  220. @Override
  221. public BisInspAllRlationPers loginByCode(String phone, String code) {
  222. DdMessageParam ddMessageParam = new DdMessageParam();
  223. ddMessageParam.setPhone(phone);
  224. ddMessageParam.setCode(code);
  225. // 查看是否有对应的 手机-短信验证码
  226. List<DdMessage> list = ddMessageDao.findList(ddMessageParam);
  227. if (null != list && list.size() > 0) {
  228. DdMessage message = list.get(0);
  229. BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
  230. param.setMobilenumb(phone);
  231. // 获取用户信息
  232. BisInspAllRlationPers pers = bisInspAllRlationPersDao.getBy(param);
  233. // 时间判断-超过未超过六分钟,则返回用户信息
  234. if (null != pers && StringUtils.isNotBlank(pers.getGuid())
  235. && null != message && StringUtils.isNotBlank(message.getId())) {
  236. long access = message.getAccessTime().getTime();
  237. long now = System.currentTimeMillis();
  238. long nm = 1000 * 60 * 10;
  239. if (nm > now - access) {
  240. pers.setPwd(null);
  241. return getOne(pers.getGuid());
  242. }
  243. }
  244. }
  245. return null;
  246. }
  247. @Override
  248. public boolean createWork() {
  249. boolean bol = true;
  250. try {
  251. PinYin pin = new PinYin();
  252. String backgroundPath1 = "";
  253. String qrCodePath1 = "";
  254. List<BisInspAllRlationPers> list = bisInspAllRlationPersDao.getZjList();
  255. for (BisInspAllRlationPers per : list) {
  256. String persId = per.getGuid();
  257. String cName = per.getPersName();
  258. cName = cName.trim();
  259. String eName = pin.getPingYin(cName);
  260. eName = eName.trim();
  261. String orgName = per.getOrgNm();
  262. orgName = orgName.trim();
  263. String admDuty = per.getAdmDuty();
  264. admDuty = admDuty.trim();
  265. String dpPost = per.getDppost();
  266. dpPost = dpPost.trim();
  267. String duty = "";
  268. if (!"".equals(admDuty) && !"/".equals(admDuty)) {
  269. duty = admDuty;
  270. if (!"".equals(dpPost) && !"/".equals(dpPost)) {
  271. duty += "/" + dpPost;
  272. }
  273. } else {
  274. if (!"".equals(dpPost) && !"/".equals(dpPost)) {
  275. duty = dpPost;
  276. }
  277. }
  278. System.out.println(cName + "--制作开始");
  279. String idNm = per.getIdnm();
  280. String outPutPath = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-竖版正面.jpg";
  281. QRCodeUtil.encode(workUrl + "/sldc/work.html?pserId=" + persId, "D:\\image\\logo\\logo.png", "D:\\image\\ewm\\" + orgName, cName, true);
  282. qrCodePath1 = "D:\\image\\ewm\\" + orgName + "\\" + cName + ".jpg";
  283. String yrCodePath = getFiles("D:\\image\\ryimage", cName);
  284. backgroundPath1 = "D:\\image\\0001.jpg";
  285. overlapImage(backgroundPath1, qrCodePath1, yrCodePath, cName.trim(), eName.trim(), orgName.trim(), duty.trim(), idNm.trim(), outPutPath);
  286. String backgroundPath2 = "D:\\image\\0002.jpg";
  287. String outPutPath2 = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-竖版背面.jpg";
  288. overlapImage1(backgroundPath2, qrCodePath1, outPutPath2);
  289. backgroundPath1 = "D:\\image\\0003.jpg";
  290. outPutPath2 = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-横版正面.jpg";
  291. overlapImage2(backgroundPath1, qrCodePath1, yrCodePath, cName.trim(), eName.trim(), orgName.trim(), duty.trim(), idNm.trim(), outPutPath2);
  292. backgroundPath2 = "D:\\image\\0004.jpg";
  293. outPutPath2 = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-横版背面.jpg";
  294. overlapImage3(backgroundPath2, qrCodePath1, outPutPath2);
  295. System.out.println(cName + "--制作结束");
  296. }
  297. } catch (Exception e) {
  298. e.printStackTrace();
  299. }
  300. return bol;
  301. }
  302. @Override
  303. public int setHeadMan(BisInspAllRlation bisInspAllRlation) {
  304. return this.bisInspAllRlationPersDao.setHeadMan(bisInspAllRlation);
  305. }
  306. public String overlapImage(String backgroundPath, String qrCodePath, String yrCodePath, String cName, String eName, String orgName, String duty, String idNm, String outPutPath) {
  307. try {
  308. //设置图片大小
  309. BufferedImage background = resizeImage(898, 1252, ImageIO.read(new File(backgroundPath)));
  310. BufferedImage qrCode = resizeImage(170, 170, ImageIO.read(new File(qrCodePath)));
  311. BufferedImage yrCode = resizeImage(300, 411, ImageIO.read(new File(yrCodePath)));
  312. //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
  313. //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
  314. FontRenderContext frc = new FontRenderContext(null, true, true);
  315. Font font = new Font("微软雅黑", Font.BOLD, 40);
  316. Rectangle2D r2D = font.getStringBounds(cName, frc);
  317. int rWidth = (int) Math.round(r2D.getWidth());
  318. int rX = (int) Math.round(r2D.getX());
  319. Rectangle r = new Rectangle(0, 0, 901, 1240);
  320. int a = (r.width / 2) - (rWidth / 2) - rX;
  321. Graphics2D g = background.createGraphics();
  322. g.setColor(Color.BLACK);
  323. g.setFont(font);
  324. g.drawString(cName, r.x + a, 770);
  325. FontRenderContext frc1 = new FontRenderContext(null, true, true);
  326. Font font1 = new Font("Arial", Font.BOLD, 40);
  327. Rectangle2D r2D1 = font1.getStringBounds(eName, frc1);
  328. int rWidth1 = (int) Math.round(r2D1.getWidth());
  329. int rX1 = (int) Math.round(r2D1.getX());
  330. Rectangle r1 = new Rectangle(0, 0, 901, 1210);
  331. int a1 = (r1.width / 2) - (rWidth1 / 2) - rX1;
  332. g.setFont(font1);
  333. g.drawString(eName, r1.x + a1, 817);
  334. g.setFont(getFont(orgName, "宋体", 28));
  335. g.drawString(orgName, 317, 895);
  336. g.setFont(getFont(duty, "宋体", 28));
  337. g.drawString(duty, 317, 957);
  338. g.setFont(getFont(idNm, "Arial", 28));
  339. g.drawString(idNm, 317, 1023);
  340. //在背景图片上添加二维码图片
  341. g.drawImage(qrCode, 655, 862, qrCode.getWidth(), qrCode.getHeight(), null);
  342. g.drawImage(yrCode, 296, 300, yrCode.getWidth(), yrCode.getHeight(), null);
  343. g.dispose();
  344. QRCodeUtil.mkdirs(outPutPath);
  345. ImageIO.write(background, "jpg", new File(outPutPath));
  346. File outPutPath_file = new File(outPutPath);
  347. // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
  348. } catch (Exception e) {
  349. e.printStackTrace();
  350. }
  351. return null;
  352. }
  353. public Font getFont(String val, String fontStr, int fontSize) {
  354. FontRenderContext frc = new FontRenderContext(null, true, true);
  355. Font font = new Font(fontStr, Font.BOLD, fontSize);
  356. Rectangle2D r2D = font.getStringBounds(val, frc);
  357. int w = (int) Math.round(r2D.getWidth());
  358. int iw = 276;
  359. while (w > iw) {
  360. font = new Font(fontStr, Font.BOLD, fontSize--);
  361. r2D = font.getStringBounds(val, frc);
  362. w = (int) Math.round(r2D.getWidth());
  363. }
  364. return font;
  365. }
  366. public String overlapImage1(String backgroundPath, String qrCodePath, String outPutPath) {
  367. try {
  368. //设置图片大小
  369. BufferedImage background = resizeImage(898, 1252, ImageIO.read(new File(backgroundPath)));
  370. BufferedImage qrCode = resizeImage(250, 250, ImageIO.read(new File(qrCodePath)));
  371. //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
  372. //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
  373. Graphics2D g = background.createGraphics();
  374. //在背景图片上添加二维码图片
  375. g.drawImage(qrCode, 320, 330, qrCode.getWidth(), qrCode.getHeight(), null);
  376. g.dispose();
  377. ImageIO.write(background, "jpg", new File(outPutPath));
  378. File outPutPath_file = new File(outPutPath);
  379. // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
  380. } catch (Exception e) {
  381. e.printStackTrace();
  382. }
  383. return null;
  384. }
  385. public String overlapImage2(String backgroundPath, String qrCodePath, String yrCodePath, String cName, String eName, String orgName, String duty, String idNm, String outPutPath) {
  386. try {
  387. //设置图片大小
  388. BufferedImage background = resizeImage(1075, 709, ImageIO.read(new File(backgroundPath)));
  389. BufferedImage qrCode = resizeImage(150, 150, ImageIO.read(new File(qrCodePath)));
  390. BufferedImage yrCode = resizeImage(196, 276, ImageIO.read(new File(yrCodePath)));
  391. //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
  392. //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
  393. FontRenderContext frc = new FontRenderContext(null, true, true);
  394. Font font = new Font("微软雅黑", Font.BOLD, 40);
  395. Rectangle2D r2D = font.getStringBounds(cName, frc);
  396. int rWidth = (int) Math.round(r2D.getWidth());
  397. int rX = (int) Math.round(r2D.getX());
  398. Rectangle r = new Rectangle(0, 0, 775, 709);
  399. int a = (r.width / 2) - (rWidth / 2) - rX;
  400. Graphics2D g = background.createGraphics();
  401. g.setColor(Color.BLACK);
  402. g.setFont(font);
  403. g.drawString(cName, r.x + a, 273);
  404. FontRenderContext frc1 = new FontRenderContext(null, true, true);
  405. Font font1 = new Font("Arial", Font.BOLD, 40);
  406. Rectangle2D r2D1 = font1.getStringBounds(eName, frc1);
  407. int rWidth1 = (int) Math.round(r2D1.getWidth());
  408. int rX1 = (int) Math.round(r2D1.getX());
  409. Rectangle r1 = new Rectangle(0, 0, 775, 709);
  410. int a1 = (r1.width / 2) - (rWidth1 / 2) - rX1;
  411. g.setFont(font1);
  412. g.drawString(eName, r1.x + a1, 320);
  413. g.setFont(getFont(orgName, "宋体", 28));
  414. g.drawString(orgName, 350, 396);
  415. g.setFont(getFont(duty, "宋体", 28));
  416. g.drawString(duty, 350, 451);
  417. g.setFont(getFont(idNm, "Arial", 28));
  418. g.drawString(idNm, 350, 508);
  419. //在背景图片上添加二维码图片
  420. g.drawImage(qrCode, 835, 395, qrCode.getWidth(), qrCode.getHeight(), null);
  421. g.drawImage(yrCode, 808, 106, yrCode.getWidth(), yrCode.getHeight(), null);
  422. g.dispose();
  423. ImageIO.write(background, "jpg", new File(outPutPath));
  424. File outPutPath_file = new File(outPutPath);
  425. // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
  426. } catch (Exception e) {
  427. e.printStackTrace();
  428. }
  429. return null;
  430. }
  431. public String overlapImage3(String backgroundPath, String qrCodePath, String outPutPath) {
  432. try {
  433. //设置图片大小
  434. BufferedImage background = resizeImage(1075, 709, ImageIO.read(new File(backgroundPath)));
  435. BufferedImage qrCode = resizeImage(200, 200, ImageIO.read(new File(qrCodePath)));
  436. //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
  437. //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
  438. Graphics2D g = background.createGraphics();
  439. //在背景图片上添加二维码图片
  440. g.drawImage(qrCode, 795, 330, qrCode.getWidth(), qrCode.getHeight(), null);
  441. g.dispose();
  442. ImageIO.write(background, "jpg", new File(outPutPath));
  443. File outPutPath_file = new File(outPutPath);
  444. // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
  445. } catch (Exception e) {
  446. e.printStackTrace();
  447. }
  448. return null;
  449. }
  450. public String getFiles(String path, String name) {
  451. String fileName = "";
  452. File file = new File(path);
  453. // 如果这个路径是文件夹
  454. if (file.isDirectory()) {
  455. // 获取路径下的所有文件
  456. File[] files = file.listFiles();
  457. for (int i = 0; i < files.length; i++) {
  458. File fl = files[i];
  459. // 如果还是文件夹 递归获取里面的文件 文件夹
  460. if (files[i].isDirectory()) {
  461. fileName = getFiles(files[i].getPath(), name);
  462. if (org.apache.commons.lang3.StringUtils.isNotEmpty(fileName)) {
  463. break;
  464. }
  465. } else {
  466. if (fl.getPath().contains(name)) {
  467. fileName = fl.getPath();
  468. break;
  469. }
  470. }
  471. }
  472. } else {
  473. if (file.getPath().contains(name)) {
  474. fileName = file.getPath();
  475. }
  476. }
  477. return fileName;
  478. }
  479. public BufferedImage resizeImage(int x, int y, BufferedImage bfi) {
  480. BufferedImage bufferedImage = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);
  481. bufferedImage.getGraphics().drawImage(
  482. bfi.getScaledInstance(x, y, Image.SCALE_SMOOTH), 0, 0, null);
  483. return bufferedImage;
  484. }
  485. @Override
  486. public int changePassword(String id, String password, String newPassword) {
  487. BisInspAllRlationPers user = bisInspAllRlationPersDao.get(id);
  488. if (null == user || StringUtils.isBlank(user.getGuid())) {
  489. //用户不存在
  490. return 0;
  491. }
  492. if (!password.equals(user.getPwd())) {
  493. //原密码错误
  494. return 2;
  495. }
  496. user.setPwd(newPassword);
  497. bisInspAllRlationPersDao.update(user);
  498. return 1;
  499. }
  500. @Override
  501. public void updateUser(List<UserRoleParam> userRoleParams, UserRoleParam param) {
  502. logger.info(" start delete user role ");
  503. userRoleDao.deleteByUserId(param.getUserId());
  504. logger.info("delete user role ");
  505. /*if (null != userRoleParams && userRoleParams.size() > 0) {
  506. userRoleDao.addList(userRoleParams);
  507. }*/
  508. logger.info(" start insert user role ");
  509. if (null != userRoleParams && userRoleParams.size() > 0) {
  510. for (UserRoleParam userRoleParam : userRoleParams) {
  511. UserRole userRole = new UserRole();
  512. userRole.setUserId(userRoleParam.getUserId());
  513. userRole.setRoleId(userRoleParam.getRoleId());
  514. userRoleDao.insert(userRole);
  515. }
  516. }
  517. logger.info(" end insert user role ");
  518. }
  519. @Override
  520. public int selectCountOnlinePers(String sttm, String entm, String province) {
  521. return bisInspAllRlationPersDao.selectCountOnlinePers(sttm, entm, province);
  522. }
  523. @Override
  524. public List<HashMap<String, Object>> selectOnlinePers(String sttm, String entm, String orgId) {
  525. return bisInspAllRlationPersDao.selectOnlinePers(sttm, entm, orgId);
  526. }
  527. @Override
  528. public GroupLeaderDto getLeaderByGroup(GroupLeaderParam groupLeaderParam) {
  529. return this.bisInspAllRlationPersDao.getLeaderByGroup(groupLeaderParam);
  530. }
  531. @Override
  532. public BisInspAllRlationPers getById(String id) {
  533. return getOne(id);
  534. }
  535. @Override
  536. public PageInfo<PersListDto> findPersData(BisInspAllRlationPersParam p) {
  537. PageHelper.startPage(p);
  538. List<PersListDto> list = this.bisInspAllRlationPersDao.findPersData(p);
  539. PageInfo<PersListDto> pageInfo = new PageInfo(list);
  540. return pageInfo;
  541. }
  542. @Override
  543. public PageInfo<PersListDto> listByCurUser(UserListByCurUserParam param, String addvcd) throws Exception {
  544. BisInspAllRlationPers per = bisInspAllRlationPersDao.get(param.getCurUserId());
  545. if (per == null) {
  546. throw new Exception("此用户不存在:" + param.getCurUserId());
  547. }
  548. if (per.getOwnerSystem() == null) {
  549. throw new Exception("用户所属系统不正确:" + per.getOwnerSystem());
  550. }
  551. List<String> systemList = new ArrayList<>();
  552. if (!SystemFlagEnum.DC_ALL.getValue().equals(per.getOwnerSystem())) {
  553. systemList.add(per.getOwnerSystem());
  554. }
  555. PageHelper.startPage(param.getPageNum(), param.getPageSize());
  556. List<PersListDto> list = bisInspAllRlationPersDao.listByCurUser(param.getPersName(), systemList,
  557. param.getPhoneIsNull(), param.getMobilenumb(), param.getOrgNm(), param.getOrgId(), param.getProvince(), param.getDpnm(), param.getPlanDpId());
  558. for (PersListDto persListDto : list) {
  559. persListDto.setPwd("***");
  560. if (StringUtils.isNotBlank(persListDto.getOrgNames())) {
  561. persListDto.setOrgNm(persListDto.getOrgNames());
  562. if (StringUtils.isNotBlank(persListDto.getPlanDpId()) && "37".equals(addvcd)) {
  563. BisInspPlanDp bisInspPlanDp = bisInspPlanDpService.get(persListDto.getPlanDpId());
  564. if (bisInspPlanDp != null) {
  565. persListDto.setPlanDpNm(bisInspPlanDp.getDpName());
  566. }
  567. }
  568. }
  569. //手机号脱敏处理
  570. persListDto.setMobilenumb(UserMsgSectrityUtils.blurPhoneNotExc(persListDto.getMobilenumb()));
  571. }
  572. return new PageInfo<PersListDto>(list);
  573. }
  574. @Override
  575. public PageInfo<PersListDto> listByCurUser(UserListByCurUserParam param) throws Exception {
  576. BisInspAllRlationPers per = bisInspAllRlationPersDao.get(param.getCurUserId());
  577. if (per == null) {
  578. throw new Exception("此用户不存在:" + param.getCurUserId());
  579. }
  580. if (per.getOwnerSystem() == null) {
  581. throw new Exception("用户所属系统不正确:" + per.getOwnerSystem());
  582. }
  583. List<String> systemList = new ArrayList<>();
  584. if (!SystemFlagEnum.DC_ALL.getValue().equals(per.getOwnerSystem())) {
  585. systemList.add(per.getOwnerSystem());
  586. }
  587. PageHelper.startPage(param.getPageNum(), param.getPageSize());
  588. List<PersListDto> list = bisInspAllRlationPersDao.listByCurUser(param.getPersName(), systemList,
  589. param.getPhoneIsNull(), param.getMobilenumb(), param.getOrgNm(), param.getOrgId(), param.getProvince(), param.getDpnm(), param.getPlanDpId());
  590. for (PersListDto persListDto : list) {
  591. if (StringUtils.isNotBlank(persListDto.getOrgNames())) {
  592. persListDto.setOrgNm(persListDto.getOrgNames());
  593. }
  594. //手机号脱敏处理
  595. persListDto.setMobilenumb(UserMsgSectrityUtils.blurPhoneNotExc(persListDto.getMobilenumb()));
  596. }
  597. return new PageInfo<PersListDto>(list);
  598. }
  599. @Override
  600. public BisInspAllRlationPers getCurUser(String id) {
  601. return bisInspAllRlationPersDao.get(id);
  602. }
  603. @Autowired
  604. private BisInspPersOrgDao inspPersOrgDao;
  605. @Override
  606. public void updatePersState(String guid, String isEnable) {
  607. this.bisInspAllRlationPersDao.updatePersState(guid, isEnable);
  608. }
  609. @Override
  610. public void updateUserNode(String guid, String persType, String orgId) {
  611. //修改用户类型
  612. BisInspAllRlationPers pers = bisInspAllRlationPersDao.get(guid);
  613. if (orgId.equals(pers.getOrgId())) {
  614. this.bisInspAllRlationPersDao.updatePersTypeById(guid, persType);
  615. }
  616. BisInspPersOrgParam persOrgParam = new BisInspPersOrgParam();
  617. persOrgParam.setPersId(guid);
  618. persOrgParam.setOrgId(orgId);
  619. BisInspPersOrg inspPersOrg = inspPersOrgDao.getBy(persOrgParam);
  620. if (inspPersOrg == null) {
  621. inspPersOrg = new BisInspPersOrg();
  622. inspPersOrg.setOrgId(orgId);
  623. inspPersOrg.setUserType(persType);
  624. inspPersOrg.setPersId(guid);
  625. inspPersOrgDao.insert(inspPersOrg);
  626. } else {
  627. inspPersOrg.setOrgId(orgId);
  628. inspPersOrg.setUserType(persType);
  629. inspPersOrg.setPersId(guid);
  630. inspPersOrgDao.update(inspPersOrg);
  631. }
  632. //根据用户id获取用户信息
  633. //获取人员所属类型
  634. List<PersTypeDto> persTypeByPersid = this.supervisionPlanDao.getPersTypeByPersid(guid, orgId, inspOrgService.getProvince(orgId));
  635. if (persTypeByPersid.size() > 0) {
  636. if ("1".equals(persType) || "2".equals(persType)) {
  637. //管理员或者机构领导
  638. for (PersTypeDto persTypeDto : persTypeByPersid) {
  639. String s = persTypeDto.getId() + orgId;
  640. OlBisInspOrg bisInspOrg = inspOrgService.get(orgId);
  641. if ("027".equals(orgId) || "029".equals(orgId) || "041".equals(orgId)) {
  642. s = persTypeDto.getId();
  643. }
  644. //查询是否存在该节点
  645. BisInspAllDto bisInspAllDto = this.bisInspAllRlationPersDao.getNodeInfo(s);
  646. if (bisInspAllDto != null) {
  647. //查询是否已经建立关系
  648. BisInspAllRlation bisInspAllRlation = null;
  649. if (!bisInspOrg.getRlcode().startsWith(AdCodeLabel.START_PARENT_ADCODE)) {
  650. bisInspAllRlation = bisInspAllRlationPersDao.getRelationData(guid, s, orgId, bisInspOrg.getRlcode());
  651. } else {
  652. bisInspAllRlation = bisInspAllRlationPersDao.getRelationData(guid, s, "", "");
  653. }
  654. if (bisInspAllRlation == null) {
  655. String type = Integer.parseInt(s.substring(0, 3)) + "";
  656. this.bisInspAllRlationPersDao.insertRelation(guid, s, orgId, bisInspOrg.getRlcode(), type);
  657. }
  658. }
  659. }
  660. }
  661. }
  662. }
  663. @Autowired
  664. private BisInspOrgDao bisInspOrgDao;
  665. @Autowired
  666. private OlBisInspOrgService inspOrgService;
  667. @Autowired
  668. private BisInspPersOrgService persOrgService;
  669. // 返回一个用户信息
  670. @Override
  671. public BisInspAllRlationPers getOne(String persId) {
  672. BisInspAllRlationPers allRlationPers = bisInspAllRlationPersDao.get(persId);
  673. if (null != allRlationPers && StringUtils.isNotBlank(allRlationPers.getOrgId())) {
  674. BisInspOrg inspOrg = bisInspOrgDao.get(allRlationPers.getOrgId());
  675. if (inspOrg == null) {
  676. return allRlationPers;
  677. }
  678. allRlationPers.setDefaultOrg(inspOrg);
  679. BisInspOrgParam inspOrgParam = new BisInspOrgParam();
  680. inspOrgParam.setPersId(allRlationPers.getGuid());
  681. List<BisInspOrg> inspOrgList = bisInspOrgDao.findPersOrgList(inspOrgParam);
  682. if (inspOrgList != null && !inspOrgList.isEmpty()) {
  683. allRlationPers.setAllOrg(inspOrgList);
  684. } else {
  685. inspOrgList = new ArrayList<>();
  686. inspOrgList.add(inspOrg);
  687. allRlationPers.setAllOrg(inspOrgList);
  688. BisInspPersOrg inspPersOrg = new BisInspPersOrg();
  689. inspPersOrg.setPersId(allRlationPers.getGuid());
  690. inspPersOrg.setOrgId(allRlationPers.getOrgId());
  691. inspPersOrg.setUserType(allRlationPers.getPersType());
  692. BisInspPersOrgParam inspPersOrgParam = new BisInspPersOrgParam();
  693. inspPersOrgParam.setOrgId(allRlationPers.getOrgId());
  694. inspPersOrgParam.setPersId(allRlationPers.getGuid());
  695. BisInspPersOrg persOrg = persOrgService.getBy(inspPersOrgParam);
  696. if (persOrg == null) {
  697. persOrgService.insert(inspPersOrg);
  698. } else {
  699. allRlationPers.setPersType(persOrg.getUserType());
  700. allRlationPers.setOrgId(persOrg.getOrgId());
  701. }
  702. }
  703. }
  704. // allRlationPers.setMobilenumb(UserMsgSectrityUtils.blurPhone(allRlationPers.getMobilenumb()));
  705. return allRlationPers;
  706. }
  707. @Override
  708. public int insertUser(BisInspAllRlationPers bisInspAllRlationPers) {
  709. BisInspPersOrg persOrg = new BisInspPersOrg();
  710. persOrg.setPersId(bisInspAllRlationPers.getGuid());
  711. persOrg.setOrgId(bisInspAllRlationPers.getOrgId());
  712. OlBisInspOrg olBisInspOrg = inspOrgService.get(bisInspAllRlationPers.getOrgId());
  713. persOrg.setUserType(bisInspAllRlationPers.getPersType());
  714. inspPersOrgDao.insert(persOrg);
  715. bisInspAllRlationPers.setOrgNm(olBisInspOrg.getOrgNm());
  716. return bisInspAllRlationPersDao.insert(bisInspAllRlationPers);
  717. }
  718. @Override
  719. public int updateData(BisInspAllRlationPers bisInspAllRlationPers) {
  720. BisInspPersOrgParam inspPersOrgParam = new BisInspPersOrgParam();
  721. inspPersOrgParam.setOrgId(bisInspAllRlationPers.getOrgId());
  722. inspPersOrgParam.setPersId(bisInspAllRlationPers.getGuid());
  723. BisInspPersOrg persOrg = inspPersOrgDao.getBy(inspPersOrgParam);
  724. if (persOrg != null) {
  725. persOrg.setUserType(bisInspAllRlationPers.getPersType());
  726. if (persOrg.getUserType() != null) {
  727. inspPersOrgDao.update(persOrg);
  728. }
  729. } else {
  730. persOrg = new BisInspPersOrg();
  731. persOrg.setUserType(bisInspAllRlationPers.getPersType() == null ? "3" : bisInspAllRlationPers.getPersType());
  732. persOrg.setPersId(bisInspAllRlationPers.getGuid());
  733. persOrg.setOrgId(bisInspAllRlationPers.getOrgId());
  734. inspPersOrgDao.insert(persOrg);
  735. }
  736. return bisInspAllRlationPersDao.update(bisInspAllRlationPers);
  737. }
  738. @Override
  739. public int selectCount(BisInspAllRlationPersParam bisInspAllRlationPersParam) {
  740. return bisInspAllRlationPersDao.selectCount(bisInspAllRlationPersParam);
  741. }
  742. @Override
  743. public LoginUser getLoginUser(BisInspAllRlationPers pers) {
  744. LoginUser loginUser = new LoginUser();
  745. loginUser.setMobile(UserMsgSectrityUtils.blurPhone(pers.getMobilenumb()));
  746. loginUser.setPersId(pers.getGuid());
  747. loginUser.setPersName(pers.getPersName());
  748. loginUser.setpType(StringUtils.isBlank(pers.getPersType()) ? "3" : pers.getPersType());
  749. return loginUser;
  750. }
  751. @Override
  752. public void sendChannel(String token, BisInspAllRlationPers bisInspAllRlationPers, HttpServletRequest request, int plusFlag) {
  753. Map<String, String> userMap = new HashMap<>();
  754. userMap.put("id", bisInspAllRlationPers.getGuid());
  755. userMap.put("userName", bisInspAllRlationPers.getPersName());
  756. userMap.put("userNum", bisInspAllRlationPers.getMobilenumb());
  757. userMap.put("password", "Jinshui@433@440");
  758. userMap.put("persType", bisInspAllRlationPers.getPersType());
  759. JSONObject jsonObject = JSONObject.fromObject(userMap);
  760. redisTemplate.convertAndSend(CommonLabel.ACTIVITI, jsonObject);
  761. userMap.clear();
  762. //向公司发送实时人员登录信息
  763. userMap.put("userName", bisInspAllRlationPers.getPersName());
  764. userMap.put("phone", bisInspAllRlationPers.getMobilenumb());
  765. userMap.put("login", plusFlag + "");
  766. OlBisInspOrg org = olBisInspOrgDao.get(bisInspAllRlationPers.getOrgId());
  767. Optional.ofNullable(org).orElseThrow(() -> new CheckException("用户的机构ID异常、未获取到对应机构"));
  768. userMap.put("orgId", bisInspAllRlationPers.getOrgId());
  769. userMap.put("orgNm", org.getOrgNm());
  770. userMap.put("orgAdCode", org.getAdCode());
  771. userMap.put("sysName", CommonLabel.SYS_NAME);
  772. userMap.put("id", token);//用token防止数据重复
  773. userMap.put("empire", JWTTokenUtil.maxAge + "");//失效时间long类型
  774. try {
  775. userMap.put("workUrl", workUrl);
  776. InetAddress ia = InetAddress.getLocalHost();
  777. String host = ia.getHostName();
  778. userMap.put("appmodel", host);
  779. if (StringUtils.isNotBlank(request.getHeader("source"))) {
  780. userMap.put("app", plusFlag + "");
  781. userMap.put("appmodel", request.getHeader("source"));
  782. } else {
  783. userMap.put("pc", plusFlag + "");
  784. userMap.put("appmodel", host);
  785. }
  786. userMap.put("ipAddr", IPUtils.getIpAddr(request));
  787. } catch (UnknownHostException e) {
  788. userMap.put("ipAddr", "IP_FAIL");
  789. }
  790. jsonObject = JSONObject.fromObject(userMap);
  791. redisTemplate.convertAndSend(CommonLabel.SEND_TO_CENTER, jsonObject);
  792. }
  793. @Autowired
  794. private BisInspAllRlationDao bisInspAllRlationDao;
  795. @Override
  796. public PageInfo<PersListDto> listByMap(Map<String, Object> paramMap) {
  797. String adCode = MapUtils.getString(paramMap, "adCode");
  798. if (StringUtils.isNotBlank(adCode)) {
  799. paramMap.put("adCode", AdLevelUtil.getAddvcd(adCode));
  800. }
  801. PageHelper.startPage(MapUtils.getIntValue(paramMap, "pageNum"), MapUtils.getIntValue(paramMap, "pageSize"));
  802. StatisticalUtil.setDate(paramMap);
  803. List<PersListDto> persList = bisInspAllRlationPersDao.listByMap(paramMap);
  804. // 循环 添加 所在组名
  805. persList.forEach(per -> {
  806. if (per.getDcNum().intValue() > 0) {
  807. // 当前人的督查次数大于0
  808. BisInspAllRlationParam bisInspAllRlationParam = Builder.of(BisInspAllRlationParam::new)
  809. .with(BisInspAllRlationParam::setPersid, per.getGuid())
  810. .with(BisInspAllRlationParam::setpType, MapUtils.getString(paramMap, "objType"))
  811. .with(BisInspAllRlationParam::setOrgId, MapUtils.getString(paramMap, "orgId"))
  812. .with(BisInspAllRlationParam::setSttm, MapUtils.getString(paramMap, "sttm"))
  813. .with(BisInspAllRlationParam::setEntm, MapUtils.getString(paramMap, "entm"))
  814. .build();
  815. Set<String> pnmArr = bisInspAllRlationDao.getPnmByPersid(bisInspAllRlationParam);
  816. per.setGroupName(String.join("、", pnmArr));
  817. //添加类别
  818. Set<String> objNameArr = bisInspAllRlationDao.getObjByPersid(bisInspAllRlationParam);
  819. per.setObjName(String.join("、", objNameArr));
  820. PersPositionLatest persPositionLatest = persPositionLatestDao.get(per.getGuid());
  821. Optional.ofNullable(persPositionLatest).ifPresent(perLatest -> {
  822. per.setCenterXGd(perLatest.getLon() == null ? "" : String.valueOf(perLatest.getLon()));
  823. per.setCenterYGd(perLatest.getLat() == null ? "" : String.valueOf(perLatest.getLat()));
  824. per.setState(DateUtils.getToday("yyyy-MM-dd")
  825. .equals(DateUtils.Date2Str(perLatest.getOperateTime(), "yyyy-MM-dd")) ? "1" : "0");
  826. });
  827. //获取人员分配的组
  828. String dcWork = "";
  829. List<BisInspAll> bisInspAlls = bisInspAllService.getPersDcWork(per.getGuid());
  830. for (BisInspAll bisInspAll : bisInspAlls) {
  831. if (bisInspAll.getSttm() == null || bisInspAll.getEntm() == null) {
  832. dcWork += " 在组" + bisInspAll.getPnm() + " 中担任:" + getName(bisInspAll.getPertype()) + "\r\n";
  833. } else {
  834. dcWork += DateUtils.Date2Str(bisInspAll.getSttm()) + "至" + DateUtils.Date2Str(bisInspAll.getEntm()) + " 在组" + bisInspAll.getPnm() + " 中担任:" + getName(bisInspAll.getPertype()) + "\r\n";
  835. }
  836. }
  837. if (dcWork.length() > 0) {
  838. dcWork = dcWork.substring(0, dcWork.length() - 1);
  839. }
  840. per.setDcWork(dcWork);
  841. }
  842. });
  843. return new PageInfo<>(persList);
  844. }
  845. public String getName(String perType) {
  846. String name = "";
  847. if (perType.equals("1")) {
  848. name = "组长";
  849. } else if (perType.equals("2")) {
  850. name = "组员";
  851. } else if (perType.equals("3")) {
  852. name = "专家";
  853. } else if (perType.equals("3")) {
  854. name = "联络员";
  855. }
  856. return name;
  857. }
  858. @Override
  859. public HashMap updateListUsers(AddRlationPersDto addRlationPersDto) {
  860. HashMap<Object, Object> map = new HashMap<>();
  861. ArrayList<UserRoleParam> userRoleParams = new ArrayList<>();
  862. BisInspAllRlationPers pers = new BisInspAllRlationPers();
  863. int allCount = 0, failCount = 0;
  864. List<String> mobilenumbList = new ArrayList<>();
  865. for (BisInspAllRlationPers bisInspAllRlationPers : addRlationPersDto.getListRlationPers()) {
  866. allCount++;
  867. if (StringUtils.isBlank(bisInspAllRlationPers.getGuid())) {
  868. bisInspAllRlationPers.setRoleIds(addRlationPersDto.getRoleIds());
  869. pers = inserts(bisInspAllRlationPers);
  870. if (pers == null) {
  871. failCount++;
  872. mobilenumbList.add(bisInspAllRlationPers.getMobilenumb());
  873. }
  874. }
  875. if (addRlationPersDto.getRoleIds().size() > 0 && addRlationPersDto.getRoleIds() != null && pers != null) {
  876. for (String roleId : addRlationPersDto.getRoleIds()) {
  877. UserRoleParam userRoleParam = new UserRoleParam();
  878. userRoleParam.setUserId(bisInspAllRlationPers.getGuid());
  879. userRoleParam.setRoleId(roleId);
  880. userRoleParams.add(userRoleParam);
  881. }
  882. }
  883. if (pers != null) {
  884. BisInspPersOrg bisInspPersOrg = new BisInspPersOrg();
  885. bisInspPersOrg.setPersId(bisInspAllRlationPers.getGuid());
  886. bisInspPersOrg.setOrgId(bisInspAllRlationPers.getOrgId());
  887. bisInspPersOrg.setUserType(bisInspAllRlationPers.getPersType());
  888. bisInspPersOrgService.insert(bisInspPersOrg);
  889. }
  890. }
  891. updateUserRole(userRoleParams);
  892. map.put("all", allCount);
  893. map.put("success", allCount - failCount);
  894. map.put("fail", failCount);
  895. map.put("failMobilenumb", mobilenumbList);
  896. return map;
  897. }
  898. @Override
  899. public void updatePassword(BisInspAllRlationPers bisInspAllRlationPers) {
  900. bisInspAllRlationPersDao.updatePassword(bisInspAllRlationPers);
  901. }
  902. private void updateUserRole(ArrayList<UserRoleParam> userRoleParams) {
  903. if (userRoleParams != null && userRoleParams.size() > 0) {
  904. userRoleDao.deleteList(userRoleParams);
  905. userRoleDao.addList(userRoleParams);
  906. }
  907. }
  908. public BisInspAllRlationPers inserts(BisInspAllRlationPers bisInspAllRlationPers) {
  909. String uuid = UuidUtil.uuid();
  910. bisInspAllRlationPers.setGuid(uuid);
  911. Assert.notNull(bisInspAllRlationPers.getPersName(), "人员姓名为必填参数");
  912. Assert.notNull(bisInspAllRlationPers.getOwnerSystem(), "所属系统为必填参数");
  913. BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
  914. param.setMobilenumb(bisInspAllRlationPers.getMobilenumb());
  915. List<BisInspAllRlationPers> list = findPage(param);
  916. if (list != null && list.size() > 0) {
  917. return null;
  918. }
  919. bisInspAllRlationPersDao.insert(bisInspAllRlationPers);
  920. return bisInspAllRlationPers;
  921. }
  922. }